How to solve the Difference between Google Maps and Geocoding? - google-maps

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.

Related

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 - Zero results for valid postal codes

I am working with the google goecode API and a few postal codes gets status ZERO_RESULTS even tho' the postal codes exists (when searching on the complete adress I can find it).
Here is the request I send (postal code: W1K6LX in England):
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:W1K6LX%7Ccountry:GB
So this gives ZERO_RESULTS
But when I search for the adress: Kalrock 20 North Audley Street I can clearly see "London W1K 6LX" right here: https://www.google.com/maps/place/Kalrock+Capital+Management/#51.5134013,-0.1556717,17z/data=!3m1!4b1!4m5!3m4!1s0x4876052eac174b5f:0xd76bd9d6e03653af!8m2!3d51.513398!4d-0.153483
Am I doing something wrong here?
It looks like there is a data issue here. The postal code W1K6LX seems to be missing in Google database.
First of all I can see that this is a valid postal code according to the Royalmail
As you mentioned the geocoding service returns ZERO_RESULTS, although the place 'Kalrock Capital Management' uses this postal code in the address. I suppose the place was created in Google My Business. If I understand correctly when you create a place in Google My Business you can enter a postal code as a text value and it will be stored, however the postal code feature might be missing from the database.
To check this theory I found the place 'Kalrock Capital Management' in Places API and figured out that the place ID is ChIJX0sXrC4FdkgRr1M24NbZa9c.
I executed geocoding request to get coordinates of this place ID:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJX0sXrC4FdkgRr1M24NbZa9c
and got coordinate 51.513398,-0.153483.
Now I try to execute reverse geocode to find the nearest postal code for this coordinate:
https://maps.googleapis.com/maps/api/geocode/json?latlng=51.513398%2C-0.153483&result_type=postal_code&key=MY_API_KEY
As you can see the nearest postal code that can be found for this coordinate is W1K 6AG
I can suggest reporting the missing postal code to Google as described in the following page
https://support.google.com/maps/answer/3094045
I hope this helps!
I think there are postcodes that are in use by the post office that are not geocodeable. I've just be trying to get a geocode for the London postcode W1S 1BN using OpenStreetMap with no luck, and yet Royal Mail's https://www.royalmail.com/find-a-postcode tells me that it relates to 17 Hanover Square. Using the identical Royal Mail tool to get the postcode for 17 Hanover Square, London, I get W1S 1HU, which is geocodable. So I'm working on the assumption that the Royal Mail creates and uses some special postcodes, probably for certain businesses or business purposes, that don't map directly to a physical location in terms of a geocode.
Using the OP's example, Royal Mail reports three different postcodes for 20 North Audley Street in London, including the two mentioned.

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

Geocoding localities (towns/cities) with Google geocoding API

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.

Google maps GeoCode API doesn't return any result at all?

This is weird. When I search something like "The New York Palace Hotel,America,New York" in Google maps app's search box I get exactly the hotel on the map.
However When I use the maps API,
A GET at http://maps.googleapis.com/maps/api/geocode/json?address=The%20New%20York%20Palace%20Hotel,America,New%20York&sensor=true
I get ZERO results in the response.
It doesn't even give New York as the option in search results.
I am making an app where I use this API to get the lat-long for user provided address.
Now, I don't know why this Google maps API doesn't work the way the Google maps app works.
BUT I wanted to know, is there a way to search and provide Google maps API these search terms as meaningful words where instead of taking whole string as one parameter it knows which city I am searching and which Address I ams searching.
If not, then only option left with me will be to Once the first results fails I make another query for city name only.
recently, i was given a similar task, and came to know the api works reverse... i.e.. we can get address for lat lon that we provide.. and that too has its own restrictions (i.e.. no.of addresses resolved per request, mostly some 2500 address per day something...)....here you can get some info over that...
You are using the Geocoding API. "The New York Palace Hotel,America,New York" is not an address, it is a "place". The Places API might be a better option.
Example of your query using the (javascript version of) the Places API