Google map sets getPlace () API only return attribute attribute for some addresses

I have an address search box using google map autocomplete library:

var autocompleter = new google.maps.places.Autocomplete(item); 

There is a strange case when the address returns only the name attribute:

 Object {name: "138 Manukau Road, Pukekohe, New Zealand"} 

But other addresses provide more data, for example:

 Object {address_components: Array[7], adr_address: "<span class="street-address">430 Queen St</span>, …n>, <span class="country-name">New Zealand</span>", formatted_address: "430 Queen St, Auckland, Auckland 1010, New Zealand", geometry: Object, icon: "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"…}address_components: Array[7]adr_address: "<span class="street-address">430 Queen St</span>, <span class="extended-address">Auckland</span>, <span class="locality">Auckland</span> <span class="postal-code">1010</span>, <span class="country-name">New Zealand</span>"formatted_address: "430 Queen St, Auckland, Auckland 1010, New Zealand"geometry: Objecthtml_attributions: Array[0]icon: "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png"id: "00fce9b1c43ac960068949cbf32eecb587b0b020"name: "430 Queen St"place_id: "ChIJQfHW8OVHDW0RyHgQRLy8fKc"reference: "CqQBlgAAAIDnkWNQ4cmU624FV6l_bAxmI27czZoytmzrrEWVaXgR5LcZuFqt1cL3WIMzoWhmZNhftRzhLUVwpFjqmw3qwKIqugj02HrvU5x6PtUvepPNPV-08pin_PvRU-__mMMH3N2vILIOLM_AnYFMqNG5MArF4ChZXJxZj6vk7PI3ORJe1W6QjIXoPgesL379E4WUCjrZ0fjv3KgqzB-G4f-8A5MSEN5S47-QZqkY5sl37cIQFWQaFLg4InSVLpYGg8n1gGO958TcA4UK"scope: "GOOGLE"types: Array[1]url: "https://maps.google.com/maps/place?q=430+Queen+St,+Auckland,+Auckland+1010,+New+Zealand&ftid=0x6d0d47e5f0d6f141:0xa77cbcbc441078c8"vicinity: "Auckland"__proto__: Object 

I found a similar problem that was raised by someone in 2012, and it looks like it was not visited.

+7
google-maps-api-3
source share
4 answers

It's amazing that the same address now returns the correct data, google should keep track of these errors and fix them as soon as possible.

+2
source share

This problem occurred intermittently for me and, as a rule, unexpectedly.

It turns out that if you get the result from Autocomplete with only the name property, you can use google.maps.places.AutocompleteService to complete the job.

For example, call this if you only return the name (by sending the input element to el)

  function getPlace(result, el, callback) { var autocompleteService = new google.maps.places.AutocompleteService(); if (result.name.length > 0) { var d = { input: result.name, offset: result.name.length }; autocompleteService.getPlacePredictions(d, function (list, status) { if (list == null || list.length == 0) callback(null); var placesService = new google.maps.places.PlacesService(el); var ref = { 'reference': list[0].reference } placesService.getDetails(ref, function (detailsResult, placesServiceStatus) { if (placesServiceStatus == google.maps.GeocoderStatus.OK) { callback(detailsResult); } else { callback(null); } }); }); } } 

It helped me a lot http://plnkr.co/edit/GF3nM3XfYX9El2w11pGo?p=preview

+3
source share

Perhaps the google service cannot geocode your address and returns only the name of the address found. The reason may be that the service does not have additional data to provide you with this address. You can simply not show this incomplete address to the user or try to geocode this address with another service, for example OSM Geocoder http://wiki.openstreetmap.org/wiki/Nominatim

+1
source share

From the Google Maps AutoFill Reference :

Returns the location details selected by the user if the data was successfully retrieved. Otherwise, it returns a Stub Place object, with the name property set to the current value of the input field .

So the answer is that the getPlace method just fails for certain places. You do not know how to solve this, but one step closer to the answer.

EDIT: FIXED IT!

For my application, I download several libraries for Google maps (geometry and locations). Reordering the library loading order fixed the problem, and I don't know why.

Edit:

 maps.googleapis.com/maps/api/js?v=3&key=[KEY]&libraries=geometry,places 

to

 maps.googleapis.com/maps/api/js?v=3&key=[KEY]&libraries=places,geometry 
+1
source share

All Articles