Google Place Autocomplete API showing invalid address - google-maps

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.

Related

Google Places API Text Search doesn't filter address correctly

I am using Google Places API Text Search to fetch for pharmacies and looks like it isn't filtering address correctly.
When I search for Walgreens, it returns some results from Broadlands, Herndon and some other locations.
If I search for Walgreens Broadlands or Walgreens Herndon, it returns nothing.
But if I search for Walgreens Miami or Walgreens Village it returns correctly.
Other strange behaviour is that, sometimes, executing the same request two times returns different results. For that reason, I don't know if you will get the same results using the links I provided.
Google documentations states the following:
The service is especially useful for making ambiguous address queries in an automated system, and non-address components of the string may match businesses as well as addresses. Examples of ambiguous address queries are incomplete addresses, poorly formatted addresses, or a request that includes non-address components such as business names.
From my understanding, the examples I gave should work just fine.
Am I missing something? What is wrong in these cases?
It sounds like a bug, I would suggest filing an issue in Google Issue tracker for Places API.
The unique workaround I can think about is providing an additional information about the area where you are searching the Walgreens pharmacy. I believe the queries with location bias work better than without it. If I use the coordinate of Broadlands (39.0181644,-77.5202688) and specify radius of 50 km, the Places API text search for Walgreens return results
https://maps.googleapis.com/maps/api/place/textsearch/json?query=walgreens&location=39.0181644%2C-77.5202688&radius=50000&type=pharmacy&region=US&key=MY_API_KEY
as shown in the screenshot
I hope this helps!

Locating current Google Place i'm at by latitude/longitude via Google Places API

i have a lat/long location data and i need to get current Google Place where i'm at now.
For example, if i'm in a shop(cafe, gym, etc..), i need to get info about THAT particular shop(cafe, gym, etc..).Or at least the closest one.
So, i'm doing it this way:
First i fetch place basic info(placeid,name, etc.) via Google Places API Nearby Search request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.7597351,-73.9836576&radius=16.66&key=...
Then i find the closest one(which is apparently where i am) and perform Place Details request with it's placeid
So, everything works fine, except for some places like the one located at 40.7597351,-73.983657 (New York Guitar lab shop) which i can see on google map, but can't get in my response. Even places that are further from my location than this, are being found fine.
I've already tried to use rankBy=distance and then checking if the result is in required radius manually, still no use. Actually, maybe this approach is right, but as told in the docs, it's required to use types parameter with rankBy=distance. So, i set types=establishment since i actually need everything except addresses and locality tokens returned. I think that the problem is some places i need, are neither counted as establishments nor as localities, but i don't know the optimal way to exclude
all types specified at (https://developers.google.com/places/documentation/supported_types) Table 2 from my response. Is there a way to get only places which types are in Table 1 (except for specifying them ALL in my types param, haha)
So, could you please help me with how can i do this?
Thanks:)
P.S. here is very similar but unaswered question
Google Places API Displaying Inaccurate Result
It seems that there's explanation here (https://developers.google.com/places/faq#why_are_some_places_never_returned_even_though_they_have_google_pages). Looks like some places are just not yet verified by Google.
And yes, the establishment is the generic category for all non-localities. So you can be sure that if you set type=establishment then you'll have as much places as you will, if you'll specify all types from Table 2. Good Luck!

Google maps api and cross locale city search

i have a website where people can buy/sell services in different cities.
I use google maps api v3, autocomplete and searchbox elements, to let them choose a city, store it in the db, and search against the db when they're buying.
Problem is, google searches are localized, so when a user looks for the same city in a different locale they won't find any match in my DB.
My solution would be to map each city to a code (much like yahoo's WOEID) and store that into my db, this way cross locale search would be ok, but i couldn't find anything like it in google maps api reference.
So, is there a way to keep using google maps, do i have to switch to yahoo, or is there another solution to cross locale searches i'm not aware of??
Thank you
Dario
If using the Places library, a search returns a PlaceResult object that has two properties that can help you:
id contains a unique identifier denoting this place. This identifier may not be used to retrieve information about this place, but can be used to consolidate data about this Place, and to verify the identity of a Place across separate searches. As ids can occasionally change, it's recommended that the stored id for a Place be compared with the id returned in later Details requests for the same Place, and updated if necessary.
reference contains a token that can be used to query the Details service in future. This token may differ from the reference used in the request to the Details service. It is recommended that stored references for Places be regularly updated. Although this token uniquely identifies the Place, the converse is not true: a Place may have many valid reference tokens.
Documentation reference
Edit:
Note: The id and reference fields are deprecated as of June 24, 2014. They are replaced by the new place ID, a unique identifier that can be used to reference specific places. The Places service in the Google Maps JavaScript API currently returns a place_id in all responses, and accepts a placeId in the Place Details request. Soon after June 24, 2015, the service will stop returning the id and reference fields in responses. Some time later, the service will no longer accept the reference in requests. We recommend that you update your code to use the new place ID instead of id and reference as soon as possible.

Getting correct address from user typed street address using google maps

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.

Google Places Autocomplete API flow

I want to use Google Places Autocomplete API to provide search-while-typing for an Android app.
the Autocomplete API returns IDs and References, requiring an iteration through the results to get the details (such as name and geometry) for each place, this is slow and results in a bad user experience. also, many API calls are done for each key press.
is there a better way to provide such searching capability with Google Places ?
Is there a reason you need to have the geometry for each possible autocomplete place after each keypress of the API? Showing this seems like generally it would not be a great user experience, and is not what the Autocomplete API was designed for.
In theory the name (description) should be enough for the user to decide which item they're interested in, and then after a user has actually selected something you can request additional details as needed.
On the other hand if you already have some information about the name of the place, you could use the Places API (not Autocomplete) to get additional details of matching nearby places:
https://developers.google.com/maps/documentation/places/#PlaceSearchResponses