【问题标题】:Google Places API field filter not applyingGoogle Places API 字段过滤器未应用
【发布时间】:2019-06-21 21:55:48
【问题描述】:

我正在请求填写“字段”参数的 Google 地方信息数据,如来自 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

【问题讨论】:

    标签: javascript api google-maps-api-3 maps


    【解决方案1】:

    Nearby Search Request 没有 fields 参数。

    您参考的文档是针对 Place Details Requests 的,而这不是您在提供的代码中使用的。

    Usage & Billing 页面还指定:

    附近搜索请求返回包含完整地点详细信息的地点列表(附近搜索请求不支持指定返回的字段)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多