我正在请求Google地方信息数据,其中填入了“ fields”参数,例如Google:https://developers.google.com/places/web-service/details#fields
我只要求3个字段:geometry, name, vicinity
。
在文档中明确指出您应至少提供1个字段: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);
});
在我的Javascript输出控制台中,我收到了太多字段:
{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
答案 0 :(得分:3)
Nearby Search Request没有fields
参数。
您引用的文档是针对 Place Details Requests 的,而不是您提供的代码中使用的文档。
Usage & Billing页面还指定:
“附近搜索”请求返回具有完整地点详细信息的地点列表(“附近搜索”请求不支持指定返回的字段)。