Geocoding localities (towns/cities) with Google geocoding API - google-maps

Is there a way to restrict the Google geocoding API to search only for settlements as opposed to full addresses? The API documentation specifies a 'components' argument but that seems intended to specify a specific locality rather than localities in general.
For example a search for the town of Maskiot in Israel..
http://maps.googleapis.com/maps/api/geocode/json?address=Maskiot&sensor=false&components=country:IL
returns 'Maskit Street' near Tel Aviv, but the actual place I'm after is miles away, as a Google Maps search shows:
https://www.google.co.uk/maps/place/Maskiyot/#32.3178645,35.502754,15z/data=!3m1!4b1!4m2!3m1!1s0x151cf24adf97e761:0x4c10482c54ff115c
Very grateful for advice.

This problem is the result of the fact that you misspelled the name of the place.
In your original request you were using "Maskiot" whereas the place is actually "Maskiyot". If you change this name in your original request it all works fine.

Related

Google Geocode API Longitude and Latitude unavailble for zip 96101

I am using google geocode api, https://developers.google.com/maps/documentation/geocoding/intro. For zipcode 96101 , it is returning "No Results Found".
Although it is avialble https://www.google.com/maps?q=96101+zip+code&um=1&ie=UTF-8&sa=X&ved=0ahUKEwid57W5k- here
Any idea?
5-digit postal codes are hard to find in the Geocoding API, sometimes even with country name, because they are surprisingly ambiguous in a worldwide context. See https://issuetracker.google.com/73030863 for more details.
There is a workaround there which is to use Places API Autocomplete with specific parameters.
Have you tried using components filtering to search a postal code? When I execute the following request, I get a postal code in the response
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A96101%7Ccountry%3AUS&key=YOUR_API_KEY
Also check if API key is correct and billing is enabled in your project. After migration to Google Maps Platform in July 2018 they are mandatory.
You can also see this result in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D%26options%3Dtrue%26in_country%3DUS%26in_postal_code%3D96101
I hope this helps!
Update
There are plenty of similar questions asked in the public issue tracker. For example, this issue:
https://issuetracker.google.com/issues/77308684
The answer from Google is the following:
Submitting a request specifying only postal code or string '11937+US' is an incomplete and ambiguous address that may lead to unexpected results.
Per documentation [1]: In the new geocoder, ambiguous, "incomplete and badly formatted queries", such as misspelled or nonexistent addresses, are prone to produce ZERO_RESULTS.
If your intent is to search postal codes in the USA please use component filters - either using region biasing or country restriction [2]:
Please also take a look at the Geocoding best practices and FAQs:
https://developers.google.com/maps/documentation/geocoding/best-practices
https://developers.google.com/maps/faq#geocoder_queryformat
[1] https://developers.google.com/maps/documentation/geocoding/faq#trbl_zero_results
[2] https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering

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.)

Google reverse geocoding - how to snap to nearest full postcode

I am using Google's reverse geocoding functionality with the maps api v3 to retrieve postal addresses for latitude longitude (when dragging a marker around a map).
This is a UK application only, and part of the system requires a full, or near full, postcode to process correctly. However the reverse geocoder regularly returns just the part of the postcode - for example "GU3", even when the actual address returned appears to be complete - for example including street and house number.
Is there anyway, preferably google but otherwise if not, of 'snapping' the address to the nearest full postcode?
I'm aware similar functionality exists for snapping to the nearest panorama view, but there appears to be no equivalent for postcode.
The UK post code database is available for download from the Ordnance Survey open data
www.ordnancesurvey.co.uk/opendata
Alternatively you can use a service like uk-postcode.com to return the closest post codes to a location
See the example at https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse
Try a UK location like 51.436951, 0.058112.
The results include an address_component of postal_code, "SE9 3AG".
It may be necessary to geocode the address you're given and then reverse-geocode the results in order to get the postcode. But it is possible.

Geocoding with Google Maps API - accuracy and limitations

It is easy to use the Google Maps API to find a specific street address and return the latitude and longitude. For example, link.
However, it appears that typing in the name of a specific location, for example a park, causes problems. Often these don't have a specific street number (at least, not easily findable). Despite the fact that Cadigal Reserve is located at the same address as in the link above, if I enter that as part of the query string and remove the street number, the results become rather useless: link
Typing this directly into maps.google.com easily finds the park itself (and of course, you could then find the latitude/longitude by looking in the URL).
Is there not any way of using the Google Maps API to geocode a park location like this?
It is important to understand that geocoding is not an exact science. The recommended practice if you have addresses that you know should geocode to a specific location is to build a cache and use local (client-side) geocoding.
In version 2 of the api you would build your own client-side cache that contains pre-computed geocoder responses by extending the GeocodeCache. Once a cache is defined, you would call the setCache() method and away you go. This is pretty much explained here:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Caching
However, AFAIK GeocodeCache was removed in V3 of the api...
So, I would suggest implementing your own client -side caching-strategy of known addresses and their corresponding coordinates. When your application receives a geocode request for a known address the response would come from your cache (rather than Google's geocoding servers).
Failing all that you can always use a payed geocoding service that, in theory, will have a much more accurate dataset (as well as a higher limit on requests, etc).
Finally, you should also take a look through the Geocoding Strategies document as it gives a good handle on some of the issues here.