Google geocode API - Zero results for valid postal codes - google-maps

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.

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 maps API does not return postal code for "Chile" based addresses

When I try to get the zipcode for an address using Google maps geocoding API, it works, the postal code is returned as part of the address_components array: (example:
https://maps.googleapis.com/maps/api/geocode/json?&address=socoma%201%2C%20marrakesh).
But for Chile (the country) based addresses, it does not seem to return the postal code:(example:
https://maps.googleapis.com/maps/api/geocode/json?&address=las%20condes%20santiago%20chile).
Any idea why would be much appreciated.
I've had a look at information about Las Condes area in wikipedia
https://en.wikipedia.org/wiki/Las_Condes
and figured out that the postal code for Las Condes should be 7550000:
https://worldpostalcode.com/chile/region-metropolitana-de-santiago/santiago/las-condes
Now I try to search the postal code 7550000 in Chile using the components filtering which is the recommended way for postal code lookup
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A7550000%7Ccountry%3ACL&key=MY_API_KEY
This request returns
{
"results":[
],
"status":"ZERO_RESULTS"
}
So, at this point it looks like the postal code 7550000 is missing from the Google database and you are experiencing a data issue. In order to fix data issue you should report it to Google following the document:
https://support.google.com/maps/answer/3094088
Hopefully, Google will add the missing postal code soon.
Google is not the answer for everything, Chile, and some other countries, has very precise postal codes.
Basically for cities, there is a postal code specific for each section of a street.
So for Las Condes, the general postal code is 7550000, but if you need the specific code for an address, you need to search on the Chile post web site
eg Acapulco street, number 3700 give postal code 7550541.
You can also use postal databases like GeoPostcodes

Google Directions API Travel Mode TRANSIT not working for street_address

Apologies if I'm writing obvious question.
Though I cannot find document anywhere online so I have decided to ask here.
Is it the case that transit mode in Goolge Directions API is only valid if origin and destination are point of interest?
If either or both address is type street_address, I am not able to receive response containing travel_mode=TRANSIT.
What I want to achieve from the API is a result like Google Map, where it outputs optimistic route between the origin and destination; consisting waypoint(s) of public transport in the middle of the trip.
E.g. Point of Interest to Point of Interest returns fine
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=Chatswood%20station&mode=transit&transit_mode=rail&key=[key]
E.g. Point of Interest to street_address returns ZERO_RESULTS
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue&mode=transit&key=[key]
E.g. Inserting "Wynyard Station" as origin and "441 Victoria Avenue" as destination in Google Map returns route including both transit and walk to the destination.
The issue with your request is that you are using incomplete address string '441 Victoria Avenue'. This is really ambiguous query. If you check it in Geocoder tool, you will see that this string is resolved to '441 Victoria Ave, Forrest City, AR 72335, USA'
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D441%2520Victoria%2520Avenue
So, you try to find a transit (train) directions between one place in Australia and another one in the USA.
ZERO_RESULTS is expected in this case. You should specify a more precise address string or use autocomplete to search transit directions using place IDs.
https://developers.google.com/maps/faq#geocoder_queryformat
https://developers.google.com/maps/documentation/geocoding/best-practices
For example, using '441 Victoria Avenue, Sydney' I can get transit directions
https://maps.googleapis.com/maps/api/directions/json?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train&key=YOUR_API_KEY
You can check this in Directions calculator tool:
https://directionsdebug.firebaseapp.com/?origin=Wynyard%20station&destination=441%20Victoria%20Avenue%2C%20Sydney&mode=transit&alternatives=true&transit_mode=train
Hope it helps!

How to solve the Difference between Google Maps and Geocoding?

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.

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.