简体   繁体   中英

Google Maps API Geocoder doesn't return location by placeId

I use AutocompleteService.getPlacePredictions method to get autocomplete items for my drop down. Very often that method returns "long" placeIds that look like this (actual placeId):

ChIJx55rzdwQ9YgRHB-NARRWZyuaBjAxNzExIERvbm5hIEx5bm4gRHJpdmUsIFNteXJuYSwgR0EsIFVuaXRlZCBTdGF0ZXM

If I then try to pass that place ID to Geocoder I get status of ZERO_RESULTS and no places:

new google.maps.Geocoder().geocode(
  { placeId: "thatLongPlaceId"},
  function (results, status) { /* no place data returned */ });

But at the same time if I make the following GET call the same placeId returns the expected address:

https://maps.googleapis.com/maps/api/place/details/json?key=MyApiKey&placeid=ChIJx55rzdwQ9YgRHB-NARRWZyuaBjAxNzExIERvbm5hIEx5bm4gRHJpdmUsIFNteXJuYSwgR0EsIFVuaXRlZCBTdGF0ZXM

What am I doing wrong? What's the proper way of using that long place ID to get place data?

I think the autocomplete endpoint is not returning valid placeids as of today or yesterday. I'm running into a similar problem.

See Google Place Autocomplete API returning wrong place id

The ZERO_RESULTS problem isn't because of the long place ids. To see this, try using the (long) place id from an autocomplete result for an address in Sydney, for eg

ChIJr-__yjeuEmsR3RMEBNOoUn-aBjQ0OCBQaXJyYW1hIFJvYWQsIFB5cm1vbnQsIE5ldyBTb3V0aCBXYWxlcywgQXVzdHJhbGlh

The call to Geocoder.geocode should return 1 result.

Long story short, the Geocoding API (that google.maps.Geocoder uses) hasn't been fixed for the problem in https://code.google.com/p/gmaps-api-issues/issues/detail?id=11107 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM