I implemented some kind of address validation using Google autocomplete query and for some of the search requests I getting ZERO_RESULT, and based on the docs it means :
ZERO_RESULTS indicates that the search was successful but returned no results. This may occur if the search was passed a bounds in a remote location.
My question is about the second part of this statement: This may occur if the search was passed a bounds in a remote location.
I couldn't find any more details about this part, what is that mean?
I'm asking because the address that I used to test the validation and return ZERO_RESULT is a valid address, I can actually find it in google maps.
This may occur if the search was passed a bounds in a remote location means that the area the autocomplete was searching didn't have any results that matched the query.
The bounds would be "the region defined by location and radius".
This would be more likely to occur with strictbounds.
Related
We are currently trying the Google places autocomplete api, but it seems as though Google places autocomplete api also returns invalid (non existent) addresses in the search result.
We want to receive only valid / actual addresses when the user types in the address autocomplete, is there a way to do it?
I searched the api docs but couldn't find anything much helpful.
There is a google places validation api but it only validates after given a single address, but we want to show only valid/actual addresses on search autocomplete and also don't want to call validation api for each of the search result items.
Went through official doc and also experimented several stackoverflow answers but those didn't match our requirements.
SO ref-1
This is Working as Intended as of now
I tried reproducing the Autocomplete request using this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=address&key=API_KEY
And the results returned has a long Place ID.
According to the Places API documentation:
"Place IDs uniquely identify a place in the Google Places database and on Google Maps."
The documentation also says that the API may return a different place ID in the response. These place ID types include:
Street addresses that do not exist in Google Maps as precise addresses, but are inferred from a range of addresses.
Segments of a long route, where the request also specifies a city or locality.
Intersections.
Places with an address component of type subpremise.
These IDs often take the form of a long string.
This explains why the API still returned a street address for the input =332 Kennedy drive, Torrington, CT using types=address. The use case of autocomplete is to help the users obtain the closest result even if they are requesting an ambiguous query. So the Autocomplete always tries to return the closest result to their input and types. In your case, it returned a street addresses that do not exist in Google Maps as precise addresses, but are inferred from a range of addresses.
There's a public bug on the issue tracker that is somehow related to this. On the comment #5, it says that:
Suggestions are sometimes created for addresses that may not exist, if there are chances that they do.
Retrieving details for such suggestions may result in the suggested address, if it actually exists or can be synthesized from existing data. Otherwise, the result may be a different address, one that actually exists.
Possible workaround
One thing you can do is to use the validation API.
But since you mentioned that you don't want to use it, I tried the Autocomplete request using this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=establishment&key=API_KEY
I just changed the types=address to types=establishment and it seems to return legit addresses. I'm not sure if this would fit on your use case, so you can just comment down if it does not.
And if it does not, I found a similar public bug on the issue tracker which says that similar issues like these are currently being worked on by the Google engineers internally. So what I would advise you to do wait for on update from this public bug.
There's no definite timeline on how long this will be fixed, but you can star it to be notified whenever there's an update.
Hope this helps!
== UPDATE ==
I tried playing around with the types and got to a point where I tried putting an array of types from this table. I tried this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=street_address|street_number|premise&key=API_KEY
and it did return some real addresses. I changed the types=address to types=street_address|street_number|premise. You could try it out yourself and play around with the types and see if it works for your use case.
for more information about types, here's a link to the documentation.
I am facing a problem which relates to geocoding in which using google geocode map api with given lat,lng (for example 32.983025 75.710981),the return result gives status as ZERO_RESULT. How can we handle this find to find the address for that particular lat,lng, which should be understandable by the end user.
You can check the status of the returned result. If the status is not OK then you can give an error message saying that the address was not found.
<status>OK</status>
You can also validate the input and inform the user that it needs to be in "lat, lon" format
Can check the status but it will be not user friendly as the address might be there but google map doesn't suggest any address as it might not be added or it might be newly added to map. So in order to handle you will check the status from the geode api and validate before showing to the end user.
The Google Maps API documents online for their Geocode API states:
Generally, only one entry in the "results" array is returned for
address lookups,though the geocoder may return several results when
address queries are ambiguous.
However if you hit this example for 'Smith Street' (that counts as ambiguous, right?) you only get one result.
https://maps.googleapis.com/maps/api/geocode/json?address=smith%20street&components=country:GB
So if Smith Street isn't ambiguous, what is? Or is the reality that this API only ever returns one result?
The docs are so misleading when it insinuates that you can search for places and get all locations based on a place name or ambiguous address. Actually, they always returned either zero or one result only in all my trials.
Example:
*Searching "KFC" returns zero results!
*Searching "KFC berlin" returns one result!
In summary, if you don't have a precise address, do not use geocoding to retrieve lats and longs period!
Instead, you should use "Place search", explained Here.
Why?
If you check this Google Maps API blog, it says:
The Geocoding API is best for handling unambiguous queries such as complete postal address strings.
Geocoding API is not recommended if your application handles ambiguous or incomplete queries, such as “123 Main St”, or if it handles queries that may contain non-address information such as apartment numbers or business names.
However, the "Place search" using Places API is much smarter at searching Semantic locations and addresses, including businesses and points of interest.
If you want to make the user search for places using GUI, you can use "Places autocomplete", but they also would mark a single location on the map based on the exact choice the user selects from the autocomplete list. You can find a tutorial Here
I have implemented Google Places API with autocomplete and Google Geocoding Api. The problem is that it seems that the results do not work correctly.
Sometimes some of the choosen results from the autocomplete list do not geocode at all, all i get is the status ZERO_RESULTS.
I know that there could be some problems regarding the fact that Google Autocomplete uses also Places, while Google Geocode uses only postal codes, but how could i limit autocomplete to give me only postal codes results.
Place Types
You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types. The supported types are:
geocode instructs the Place Autocomplete service to return only geocoding (address) results. Generally, you use this request to disambiguate results where the location specified may be indeterminate.
establishment instructs the Place Autocomplete service to return only business results.
the (regions) type collection instructs the Places service to return any result matching the following types:
locality
sublocality
postal_code
country
administrative_area1
administrative_area2
the (cities) type collection instructs the Places service to return results that match either locality or administrative_area3.
Hope this helps
https://developers.google.com/places/documentation/autocomplete
There is no way to achieve it via an Autocomplete.
When you type in a autocomplete the API first will request the predictions, but not the details.
This means that at the time when you see the predictions it's still not clear if there are details available for this place.
There are cases when the particular place can't be found. I'm sure when it would be possible for google to exclude the missing places they wouldn't return them at all.
The only workaround I see would be to create the autocomplete on your own by requesting both, predictions and details , before you apply the predictions. But note: each time the user types into the input this will count as 6 requests(assuming 5 predictions will be returned)
I've never used the google-maps api, but I just want to do one particular thing.
I've got around 1000 user typed street addresses. Some are missing states and postcodes. I've noticed if I type these addresses into google maps it generally gives me back the state and postcode (only very rarely it gives some options). Is there a way to do this programatically, so I don't have to manually copy/paste this in? Has someone already made an application/library to do this that I can just feed the user typed data to?
Edit:
I've noticed this does the job:
https://maps.google.com.au/maps?q=1%20George%20st%20sydney
It returns state and postcode. But it returns it on a webpage with a whole lot of other stuff. I just want the address only. I guess I could grep through the results, but some additional thing to add to the query string so it only returns the raw address (or some structure) would be useful.
You can use the Geocoding API - https://developers.google.com/maps/documentation/geocoding/
E.g. http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1%20George%20st%20sydney ; you can replace "json" with "xml" if you prefer. Look for "formatted_address" in the result, or individual address components, depending on what you need.
However, I'm quite frustrated that it sometimes doesn't work, even for some cases where the regular google maps search is successful.