javascript - Google Places API field filter not applying
问题描述
I'm requesting a Google Places data with the "fields" parameter filled in as in example from google: https://developers.google.com/places/web-service/details#fields
I am only requesting 3 fields: geometry, name, vicinity
.
In the documentation it is clearly stated you should provide at least 1 field: https://developers.google.com/places/web-service/details#fields
function requestGooglePlaces(placeType) {
var request = {
fields: ['name', 'geometry', 'vicinity'],
location: location,
radius: '5000',
type: [placeType],
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
});
google.maps.event.addListener(marker, 'click', function () {
console.log(place);
var contentInfoWindows = (place.name + "<br>" + place.vicinity + "<br>" + place.geometry.location);
});
In my Javascript output console I am receiving way too much fields:
{geometry: {…}, icon: "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png", id: "5ffe179c6015e35e796ff313a35ff5149efd396d", name: "Carrefour market", opening_hours: {…}, …}
geometry: {location: _.Q, viewport: _.R}
html_attributions: []
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png"
id: "5ffe179c6015e35e796ff6f3a35ff5149efd396d"
name: "Carrefour market"
opening_hours:
open_now: false
__proto__: Object
photos: Array(1)
0: {height: 4128, html_attributions: Array(1), width: 2322, getUrl: ƒ}
length: 1
__proto__: Array(0)
place_id: "ChIJx3_zP3I8w0cR5i6Q99tFeCU"
plus_code: {compound_code: "V84J+X6 Harelbeke, Belgium", global_code: "9F25V84J+X6"}
rating: 4.4
reference: "ChIJx3_zP3I8w0cR5i6Q99tFeCU"
scope: "GOOGLE"
types: (7) ["supermarket", "bakery", "grocery_or_supermarket", "store", "point_of_interest", "food", "establishment"]
user_ratings_total: 22
vicinity: "Mainstreet 137, NY"
__proto__: Object
解决方案
推荐阅读
- vba - 在 R1C1 公式中使用时,带小数的变量会转换为 2 位数字
- r - 在不丢失信息的情况下减少数据
- javascript - Scriptable Java Transform Spring 云数据流
- lua - Lua - 难以理解 OOP
- excel - Excel 2016 VBA - 状态栏未显示完整消息
- angularjs - $scope.$on $locationChangeStart 保留 URL 但显示新视图
- java - Spring boot 2 - REST 控制器测试在 org.springframework.hateoas.PagedResources 上引发异常
- java - 为什么根据 Cmake,Java OpenCV 模块不可用?
- prometheus - 为什么在没有匹配原始数据的情况下`count_over_time`会增加?
- javascript - React Native:从一个类获取数据到另一个类