I need a reliable method to get the city, state and country place_id from latitude and longitude.
I'm trying by using Google Maps geocode, but the problem is that some coordinates don't return the administrative_level_1 (state) or the country.
Take this GET request for instance:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-25.4364413,-49.2839333&result_type=country&key=YOUR_API_KEY
It returns:
{
"results": [],
"status": "ZERO_RESULTS"
}
Did you know a way to get this results?
This is a bug and it was reported in Google issue tracker in November 2016. Please have a look at bug report and feel free to star it to add your vote.
https://issuetracker.google.com/issues/35829979
I've already added a link to this question in the bug. You can also check workarounds suggested by users in bug comments.
For example, there is following suggestion
I found a workaround:
if I do not get a country back, I will do a second reverse geocoding with the coordinates of the highest result I got.
Most of the times these coordinates will be in an area, where I can get the country.
This is not ideal, but it works for the cases I found.
I believe you might also be interested in the feature request 'Add place_id in each address_components':
https://issuetracker.google.com/issues/35827596
Feel free to star it as well.
Related
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!
Using the google geocode API I am unable to get administrative_level_1(state) information for location on border of India (Kashmir, Arunachal Pradesh, ...). Can anyone help me with this?
see issue 8450 in the issue tracker
from that issue:
http://en.wikipedia.org/wiki/List_of_territorial_disputes
In disputed areas, geocoding results have no country (and sometimes no administrative_area_level_1). Reverse geocoding for disputed areas returns no results (e.g. 34.0836581,74.7973681). There is work underway to make reverse geocoding work in disputed areas.
The reverse geocoding only returns the nearest 10 results, so, in some cases, the country is not included.
example: https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452
(this should return all the way up to the USA, but it only goes to New York)
Even if I supply the result_type=country parameter, USA won't be in the results, instead, the result array is empty:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&result_type=country
(note you'll need to add your google api key)
I did not find this behaviour documented, nor did I find any mention of it somewhere else.
Is this a limit that is enforced for free api keys or did I miss some documentation about this?
I believe this issue for reverse geocoding has already been reported in the public issue tracker:
https://issuetracker.google.com/issues/35829979
Please add your examples in the public issue and star it to receive updates from Google.
Hope it helps!
I'm a french developer and I have question about GMAP Geocoding API.
I'm on a new website work, which use this API.
The Geocoding API is used to get geocoded boundaries of french cities when user enter a french postal code.
So I request the API by this URL : https://maps.googleapis.com/maps/api/geocode/json?address=MY_ZIP_CODE&components=country:fr&key=my_key
In France, sometimes there is multiple cities for one postal code.
The default city is written in the JSON in address_components, "types" : [ "locality", "political" ] and all the cities are writtent in "postcode_localities".
(have an example in screenshot).
Last week, everything was working good.
But today, I've got a big probleme... When I use postal code (69510, 69310, 69600, etc....) multiple cities or alone city aren't no longer displayed.... But it works good for "69530".
It's embarassing for me because the website I'm bulding use the postal code to do a geolocated search with km radius...
Do you know if this API was update ?
I've search on Google.... But I've never find an answer.
Thanks in advance for your help !!
Have a nice day
My screenshot that show the API JSON answer
I was experiencing this problem as well yesterday. #xomena was right.
They updated their API at the end of November/beginning of December, and started more strictly encouraging best practices – using the Geocoding API for complete postal code strings (for example, “48 Pirrama Rd, Pyrmont, NSW, Australia”), and the Places API for more ambiguous addresses and semantic locations, including businesses and points of interest.
Specifically their blog post said:
Future Changes to Geocoding API
We plan to roll out an update to the Geocoding API at the end of November 2016 that will increase the difference between Geocoding and Places performance for ambiguous and unambiguous queries. This change will improve the quality of Geocoding results for unambiguous queries, but will be more likely to return ZERO_RESULTS for ambiguous or incomplete queries where the Geocoding API was unable to find a high quality result.
If you are already using the above best practices, you should see an improvement in your Geocoding API results. If you are currently using the Geocoding API for incomplete or ambiguous queries, or for queries that may contain non-address information such as business names or apartment numbers, we recommend that you switch to the Places API instead, as it is likely to give better quality results for your use case.
Try using the Place Search API instead! https://developers.google.com/places/web-service/search
Please file a bug in the Google Maps API issue tracker.
This is not related to the new geocoder, you'll see that adding new_forward_geocoder=false to your requests makes no difference.
The postcode_localities field is never exposed in Places API.
I am experiencing the same problem as described by #Jean-Baptiste.
I opened an issue : http://code.google.com/p/gmaps-api-issues/issues/detail?id=11087
Thanks for your answers.
That's true, the Places API can't give an autocompletion and the Autocomplete API doesn't give me satisfaction.
I've change my JS API parser and I get geocoding datas even if the postcode localities exists. If the zip code exists, so the geocoding datas exist.
That's a solution.... The visitor knows the zip code of the city where he lives. And for a major part of cities, the zip code is ok.
I saw that www.booking.com has the same problem...
Screenshot of the same problem on booking.com
That's solved for me ;-)
Thanks !!
OK here is an odd situation. This I have been facing from long time on so many Maps I have created.
Here is one sample address :
Hotel Tamisa Golf, Camino Viejo de Coín, 3, Mijas Costa, Málaga, 29649 , Spain
If we go to
maps.google.com
and search this address, it comes to the exact Hotel Tamisa Golf.
But if we use Google Map's Geocoding method using this Example provided By Google themselves, and search this address over there, it is showing totally different location. Some miles away from actual location.
http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html
Is there a way to fix this so that is should show the Exact location on Map?
That "address" is a "place" not a "postal address".
The geocoder finds the coordinates associated with a postal address, looks like it thinks the address is "Urbanización Mijas Golf, 13S, 29651 Mijas, Málaga, Spain":
geocode
The places API finds "places": place
For the address you mentioned, the geocode is returning more than one results, you need to handle all the results. see your answer here.
EDIT:
The Google Place search API can help you here, for more detail see this.
Sample example is here at jsFiffle.