【问题标题】:Google maps details API does not return fieldsGoogle 地图详细信息 API 不返回字段
【发布时间】:2019-10-02 14:54:49
【问题描述】:

我正在尝试从google maps place detail api 检索信息。

我正在调用这个网址:

https://maps.googleapis.com/maps/api/place/details/json?key=my_api_key&place_id=ChIJgQlGoRzcQUcRP8UPrtI8hcc&fields=geometry,price_level,rating,review,user_ratings_total

地点id来自地点搜索api,是this地点的id。

所以我在 url 中请求以下字段:geometry、price level、 rating、review、user_ratings_total,我的回复如下:

{
   "html_attributions" : [],
   "result" : {
      "geometry" : {
         "location" : {
            "lat" : 47.510746,
            "lng" : 19.036858
         },
         "viewport" : {
            "northeast" : {
               "lat" : 47.51209583029149,
               "lng" : 19.0382836802915
            },
            "southwest" : {
               "lat" : 47.50939786970849,
               "lng" : 19.0355857197085
            }
         }
      }
   },
   "status" : "OK"
}

几何图形显示正常,但其他字段未显示。

根据documentation,都是有效的查询参数,参数之间用逗号隔开。 文档中有三种类型的字段,所有Basic类型的字段都可以工作,另外两个Contact和Atmosphere不可以。

如何获取响应中的所有字段参数?

【问题讨论】:

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


    【解决方案1】:

    您似乎输入了错误的 place_id。您使用的 place_id 不会返回您链接到的商家。

    将Place ID Finder 用于 BlackBelt 技术 Kft 给出的 place_id 为:ChIJUxteJqfeQUcRAXhmxC6DVn0

    在查询中使用该 place_id 会返回正确的评分、评论和 user_ratings_total:

    https://maps.googleapis.com/maps/api/place/details/json?key=[yourkey]&place_id=ChIJUxteJqfeQUcRAXhmxC6DVn0&fields=geometry,price_level,rating,review,user_ratings_total

    返回:

    {
       "html_attributions" : [],
       "result" : {
          "geometry" : {
             "location" : {
                "lat" : 47.510746,
                "lng" : 19.036858
             },
             "viewport" : {
                "northeast" : {
                   "lat" : 47.51209583029149,
                   "lng" : 19.0382836802915
                },
                "southwest" : {
                   "lat" : 47.50939786970849,
                   "lng" : 19.0355857197085
                }
             }
          },
          "rating" : 4.9,
          "reviews" : [
             {
                "author_name" : "Ferenc Magnucz",
                "author_url" : "https://www.google.com/maps/contrib/106293318482835037880/reviews",
                "language" : "hu",
                "profile_photo_url" : "https://lh6.ggpht.com/-iV81elgPTlY/AAAAAAAAAAI/AAAAAAAAAAA/UtxhI3d0Hc0/s128-c0x00000000-cc-rp-mo/photo.jpg",
                "rating" : 5,
                "relative_time_description" : "a year ago",
                "text" : "Profi fejlesztők.",
                "time" : 1523996058
             },
             {
                "author_name" : "Balázs Solti",
                "author_url" : "https://www.google.com/maps/contrib/106041701773835494953/reviews",
                "language" : "hu",
                "profile_photo_url" : "https://lh5.ggpht.com/-yE-3lI1u9vo/AAAAAAAAAAI/AAAAAAAAAAA/cXsW4d_QR3Q/s128-c0x00000000-cc-rp-mo-ba5/photo.jpg",
                "rating" : 5,
                "relative_time_description" : "a year ago",
                "text" : "Családias, kellemes iroda tele jó emberekkel",
                "time" : 1511865164
             },
             {
                "author_name" : "Norbert Csaba Herczeg",
                "author_url" : "https://www.google.com/maps/contrib/117379994807862656830/reviews",
                "profile_photo_url" : "https://lh3.ggpht.com/-i2x74XtvUJM/AAAAAAAAAAI/AAAAAAAAAAA/ko28SV_gxG4/s128-c0x00000000-cc-rp-mo/photo.jpg",
                "rating" : 5,
                "relative_time_description" : "a year ago",
                "text" : "",
                "time" : 1513607989
             },
             {
                "author_name" : "Tibor Dr. Szállási",
                "author_url" : "https://www.google.com/maps/contrib/107869538624149315782/reviews",
                "profile_photo_url" : "https://lh4.ggpht.com/-6_bNC24Uwfc/AAAAAAAAAAI/AAAAAAAAAAA/XCbaj4_6gak/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
                "rating" : 5,
                "relative_time_description" : "a year ago",
                "text" : "",
                "time" : 1513852229
             },
             {
                "author_name" : "Tamas Molnar",
                "author_url" : "https://www.google.com/maps/contrib/106716196386208549131/reviews",
                "profile_photo_url" : "https://lh5.ggpht.com/-CbTBYAV3R2o/AAAAAAAAAAI/AAAAAAAAAAA/DeIEdrGy8gs/s128-c0x00000000-cc-rp-mo/photo.jpg",
                "rating" : 5,
                "relative_time_description" : "11 months ago",
                "text" : "",
                "time" : 1540533991
             }
          ],
          "user_ratings_total" : 35
       },
       "status" : "OK"
    }
    

    它没有返回价格水平,大概是因为该业务不存在该数据(它似乎不是餐厅/酒吧/咖啡馆)

    【讨论】:

      【解决方案2】:

      商家(在 Places API 中)将在其条目中包含商家名称以及地址。地址的条目不会。

      PlaceId:ChIJgQlGoRzcQUcRP8UPrtI8hcc 地址是:Budapest, Királyfürdő u. 4, 1027 Hungary

      不是企业:BlackBelt Technology Kft. at the address: Budapest, Királyfürdő u. 4, 1027 Hungary

      如果我使用Place ID Finder

      我的 PlaceId 为 ChIJUxteJqfeQUcRAXhmxC6DVn0,

      哪个有你要找的字段。

      proof of concept fiddle

      【讨论】:

        猜你喜欢
        • 2017-03-17
        • 2018-07-02
        • 1970-01-01
        • 1970-01-01
        • 2017-05-08
        • 2016-10-27
        • 1970-01-01
        • 2012-12-23
        • 1970-01-01
        相关资源
        最近更新 更多