Google maps details API does not return fields

流过昼夜 提交于 2020-01-02 22:33:28

问题


I am trying to retrieve information from the google maps place detail api.

I am calling this url:

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

The place id comes from the Place Search api, it is the id of this place.

So I am requesting the following fields in the url: geometry, price level, rating, review, user_ratings_total, and my response is the following:

{
   "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"
}

Geometry is showing up all right, but the other fields are not.

According to the documentation, they are all valid query parameters and the parameters should be separated by a comma. There are three types of fields in the documentation, all Basic type fields are working, the other two Contact and Atmosphere are not.

What do I do to get all the field parameters in the response?


回答1:


A business (in the Places API) will have the business name in its entry, as well as the address. The entries for the addresses won't.

PlaceId: ChIJgQlGoRzcQUcRP8UPrtI8hcc Is the address: Budapest, Királyfürdő u. 4, 1027 Hungary

Not the business: BlackBelt Technology Kft. at the address: Budapest, Királyfürdő u. 4, 1027 Hungary

If I use the Place ID Finder

I get a PlaceId of ChIJUxteJqfeQUcRAXhmxC6DVn0,

Which has the fields you are looking for.

proof of concept fiddle




回答2:


It looks like you have the wrong place_id. The place_id you're using doesn't return the business you link to.

Using the Place ID Finder for BlackBelt Technology Kft gives a place_id of: ChIJUxteJqfeQUcRAXhmxC6DVn0

Using that place_id in your query returns the correct rating, reviews and 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

returns:

{
   "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"
}

It does not return a price level, presumably because that data does not exist for this business (it doesn't appear to be a restaurant/bar/cafe)



来源:https://stackoverflow.com/questions/58204065/google-maps-details-api-does-not-return-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!