Location not found with Google Maps API - google-maps

I have an address that is a valid address according to the USPS...
1606 ULSTER AVE, LAKE KATRINE, NY 12449
Searching Google Maps for this address in my browser yields the proper results. However, Google Maps API yields ZERO_RESULTS:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
This is happening for about 1% of my locations. Why is the API returning separate results? How do I get it to yield the same results as the browser UI?

Perhaps if you were to validate/standardize the address before submitting it for Google geocoding you would get better results. A quick Google search for "address validation" will give you a number of good tools to do that.
#geocodezip is right that when you remove the ZIP code you get a more predictable response. That might be because the ZIP code is a numeric representation of the city/state combination and is usually regarded as a positive identifier in many tables. However, since the ZIP code can be changed at any time by the US Postal Service, a more consistent response might be obtained (if you encounter issues) by always removing the ZIP code. The problem with always removing the ZIP code is that you have now removed 20% of the address information that you have, and many times a ZIP code can trump a bad city/state combination and still get you valid results.
Consider the following somewhat invalid address: This fails:
275 north main Hollywsdfsdfsdfsdfood CA 84627
If you discard the ZIP code, you get nothing because 275 north main is not a valid address in "Hollywsdfsdfsdfsdfood CA"
However, if you keep the ZIP code and use that instead of the unlikely "Hollywsdfsdfsdfsdfood CA" as the city/state designator, you end up with a completely valid address in Ephraim, Utah 84627.
Here's an example on SmartyStreets since Google Maps was unable to handle it with the bogus city name. The validated address is:
275 N Main St Ephraim UT 84627-1107
So, going back to the idea of address validation BEFORE geocoding, you could then put that address into Google Maps and easily get your geocode. Maybe even keep your current process and then just add a separate routine for the 1% that fail.
[I deal with this kind of thing every day, I work at SmartyStreets]

This is a Places API result, not from the geocoder.
Looks like the zip code is confusing the geocoder, if I remove the zip code, it returns a result:
http://www.geocodezip.com/v3_example_geo2.asp?addr1=1606%20ULSTER%20AVE,%20LAKE%20KATRINE,%20NY&geocode=1

Related

google directions API keeps changing the destination postalcode

I am having troubles using the google directions api.
for example I want to retreive the distance between two cities, I send the following command :
https://maps.googleapis.com/maps/api/directions/json?origin=8380 Belgium&destination=2030 Belgium&sensor=false&alternatives=true&key=<mykey>
it should return details about the route between postalcode 8380 (belgium) and postalcode 2030 (belgium).
But in the result I see that google had altered postalcode 2030 into 4730 !
That is a complete different location.
See also this
If i simply use the maps url like this
http://www.google.be/maps/dir/8380 Belgium/2030 Belgium
then it works as expected.
How can I force google to NOT change the postal code into something else but keep using the postal code i send ?
EDIT
I have been playing with it and it turns out that if I use B-2030 in stead of 2030 as postalcode, it works as expected.
If I use BE-2030 it gets me close but still 15 km to far.
But using a prefix like B- on all postalcodes is something I rather not do, maybe it will work wrong on some other postal codes, and we also have a lot of foreign addresses I dont want to keep a list of all country codes...
EDIT
I had put this question as a ticket with google, I received an answer that they are aware of this issue and the developers are looking for a fix.
I will update this post when I receive more news from them.
You are right this is a known issue with 4-digit postal codes that was reported in Google issue tracker for a bunch of countries:
https://issuetracker.google.com/issues/75985322
Hopefully Google will solve it soon.
In the meantime it looks like the only reliable workaround consists in resolving the postal codes to their places IDs via place autocomplete service and applying place IDs in directions requests.
E.g. execute the place autocomplete requests for your examples:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=8380%20Belgium&types=(regions)&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=2030%20Belgium&types=(regions)&key=YOUR_API_KEY
These requests will return place ID ChIJo0saJPpVw0cRzkf6DZ5gRBo for '8380 Belgium' and place ID ChIJ4ejQlRcIxEcRnGOzGMCkbYc for '2030 Belgium'.
So, now you can execute directions request with these place IDs and get expected results
https://maps.googleapis.com/maps/api/directions/json?origin=place_id%3AChIJo0saJPpVw0cRzkf6DZ5gRBo&destination=place_id%3AChIJ4ejQlRcIxEcRnGOzGMCkbYc&mode=driving&alternatives=true&key=YOUR_API_KEY
Here is the same request in directions calculator:
https://directionsdebug.firebaseapp.com/?origin=place_id%3AChIJo0saJPpVw0cRzkf6DZ5gRBo&destination=place_id%3AChIJ4ejQlRcIxEcRnGOzGMCkbYc&mode=driving&alternatives=true
I hope this workaround might be helpful.

Google geocoding API returns ZERO_RESULTS for postal code

I am trying to geocode user entered data using the Google maps API, and got an error for the Australian postal code "2010"
maps.google.com/maps/api/geocode/json?components=country:AU|postal_code:2010
However, if I search in Google maps, I get a result. Am I doing something wrong in my request?
Your request is completely OK, but unfortunately, Google experience issues with searching 4-digit postal codes. This bug has already been reported in Google issue tracker and you can see it here:
4-digit postal codes are hard to geocode (AT, AU, BE, DK, NZ, SI)
I would suggest starring the bug to add your vote and subscribe to further notifications from Google.
Also you can see that suggested workaround by Google is using place autocomplete request with types (region) and country components filter.
So, in your case you can run the following query
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=2010&types=(regions)&components=country%3AAU&key=YOUR_API_KEY
It will return a place ID for postal code 2010: ChIJ3QyubXuuEmsREIe6P2t9ARw
And you can use geocoding with place ID to get required information
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ3QyubXuuEmsREIe6P2t9ARw&key=YOUR_API_KEY
I hope this helps!
I experienced a similar issue periodically, when geocoding US zip-codes. Appending the country name after the zip-code seemed to fix the problem. So, instead of 60162 use 60162 USA.
When a URL is opened in the browser based on its IP context, it identifies the country and automatically deduces the query format for a zip code is 99.999-99.
The format above is for Brazil, but there are different standards for each country such as USA and Portugal.
One solution when calling an API via CURL, either by code or by terminal, include the "&components = country: US" parameter, changing the "US" country code to what you want to filter.
The Google API returns ZERO_RESULTS for safety, because a search would be too slow and could do a global search worldwide and not just the country. For performance and speed reasons, Google creates this automatic ID for help, but unfortunately is not provided to developers about this process.
Good luck!

Google Geocode api returning incorrect result for a particular address

When I try to geocode one of the adress using Google geocode api, Google api returns an incorrect location.
search address : republic of estonia
result from google api: spain
I am using javascript Google api to geocode the address. For some other location the result is correct but for above address its incorrect.
If we enter below url in browser, we get the JSON back and it is showing result somewhere in Spain rather than showing result in Estonia.
http://maps.googleapis.com/maps/api/geocode/json?address=republic%20of%20estonia
I tried same addres in maps.google.com and it takes me to correct location.
Have a look at the Estonia country feature in Map Maker:
https://www.google.com/mapmaker?iwloc=0_0&fmi=0_0&gw=39&fid=5085290329182063613:4677726785527621059&dtab=overview&ll=58.620408,24.93212&spn=3.101226,8.668213&z=7&lyt=large_map_v3&htll=58.560236,25.449737&hyaw=278.7642140009582
If you check the list of names for this feature, you will see that there is no 'Republic of Estonia' in the list. The name is simply 'Estonia'.
The request for 'Estonia' works as expected:
https://maps.googleapis.com/maps/api/geocode/json?address=estonia&key=YOUR_API_KEY
If you believe that 'Republic of Estonia' must be in the list of the names please Send a feedback (bottom right corner) to Google from this page
https://www.google.com/maps/place/Estonia/#58.7223142,23.1414399,7z/data=!4m5!3m4!1s0x4692949c82a04bfd:0x40ea9fba4fb425c3!8m2!3d58.595272!4d25.013607?hl=en
Google assumed you were looking for "Calle Estonia" or "Estonia Street".
You should request that Google add "Republic of Estonia" to their list of spaces. Google, and most other mapping services, only have "Estonia" or "EST" in their list of places.
Also, you may want to use a different API if you need to get an accurate answer. Google is really good, but Google tries to "guess" what you mean and always gives you a result. But, a service like SmartyStreets matches searches to databases of addresses (so if the search is not a "real" place, it will tell you).
(Full disclosure: I have worked for SmartyStreets.)

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 Maps API: Searching

I'm working on a shipping system for my company where user's enter (along with a bunch of other information) the destination that something needs to get shipped to. The system that we are migrating from just used this information as static text, so people would enter shorthand addresses such as "Alsip 60801".
My original thought was that that sort of shorthand text would work perfectly with Google Maps API, because I can type shorthand things into maps.google.com, and it generally works.
So, I wrote up some code to run geocoding on their shorthand inputs. To my unfortunate surprise, the results returned from the geocode search were greatly different from those that are returned from maps.google.com.
For example, when I search for "Alsip 60801" on maps.google.com, I get Alsip, IL 60801. That's correct. But when I search using the Google Maps API, I get some Alsip up in Canada.
Is there another search function that I should be using for the Google Maps API? Or some sort of flag that I am missing?
For reference, this is the short version of my code:
var geocode = new google.maps.Geocoder();
geocode.geocode( {'address': 'Alsip 60801' }, function(results, status) {
console.log(results[0].geometry.location);
//Outputs the LatLng of a Canada address
});
Edit 1: I forgot to mention, I did try setting the region on the geocode request. I set it to us, and got the same results.
Update - Answered: I marked #Jitimaro's answer as correct, because tacking the country code onto the end of the results does seem to work. I'm not sure if that will work with every sort of input (it's hard to predict shorthand address formats), but it seems to work fine for now.
However, I actually am handling this a different way. Instead of just tacking a country code onto the end of the address, I'm actually providing a LatLngBounds parameter on the end of my geocode request. That gives all addresses within my bounds preferential treatment as it is searching.
When you search with the website you should get a preview like this: http://maps.google.com/maps?q=Alsip+60801. When you search a reverse geocode you must parse the result to match your country http://maps.googleapis.com/maps/geo?q=Alsip+60801. You can check the different url with a network sniffer. Or you can add the country to your url http://maps.googleapis.com/maps/geo?q=Alsip+60801+USA.