Google reverse geocoding - how to snap to nearest full postcode - google-maps

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.

Related

How to find municipality and postal code that are in range from coordinates?

Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.

Google Map API for addesses search

I have been searching for some information on what I want to achieve but not getting any clear answers.
I have a database with thousands of addresses. I want that when the user searches by entering a postcode, the search should show all the available addresses close to the postcode in a map. Zooming In would obviously show closer address to the search postcode (and hence less search results) and zooming out would also include farther addresses (and hence more search results). And then clicking the location icon would display the complete address.
Do I need to store the addresses as longitude and latitude or google map can search a location using postcode? If I need to store the longitude and latitude then whats the best way to convert an address to long and lat?
I really appreciate if you can point me to any useful links or reusable code.
Thanks
As I understand it, you want to find all closest locations from YOUR data to some location, which is identified by a postcode.
First, you have to convert all your addresses to coordinates (Latitude and Longitude). You can do that using Google Geocode API, you will have to create as script, which calls Google Geocode API for every single address in your db:
https://maps.googleapis.com/maps/api/geocode/json?address=EXAMPLE_ADDRES&key=YOUR_API_KEY
The response this script brings you is documented here. You can parse it to get latitude and longitude for each locations and store them in your database. BEWARE of limitations of the Google Geocode API. They are listed here. You have to create your script in a way that won't exceed those limits. Also read this article for caching the results of geocoding, to make sure you don't violate the terms of service. The article also contains some best practices and examples of server side geocoding.
Now, when somebody inputs postcode to your application, you can use the geocoding API or Google maps Geocoding service to translate postcode to coordinate and using haversine formula you can calculate the closest locations from your db, to coordinates of the postcode location. You can do that on frontend side, example in this SO answer (instead of address you will input postcode + state/country in the address bar) or on backend side, if you use MySQL check this SO question.

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 - Wildcard searches beyond exact matches

Anyone know if the Google Maps Geocoding service can return results including locations that start with the search term when it finds an exact match for the search term?
Here's my example
In Australia if I search for the term "Bass", I get exactly one result because there is one town in Australia called Bass. But I also want to include any other town that may start with Bass - EG "Bass Hill" and "Bassendean".
I haven't found a reference or example - any help would be appreciated!
I doesn't see any way to do this.
Found this from google geocoding reference.
How should I format my geocoder queries to maximise the number of successful requests?
The geocoder is designed to map street addresses to geographical coordinates. We therefore recommend that you format geocoder requests in accordance with the following guidelines to maximise the likelihood of a successful query:
* Specify addresses in accordance with the format used by the national postal service of the country concerned.
* Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned.
* Use the street number of a premise in preference to the building name where possible.
* Use street number addressing in preference to specifying cross streets where possible.
* Do not provide 'hints' such as nearby landmarks.
Now, given above it(google geocoding webservice) isn't going to assume the inputs given by you for some other input. It tries to map the inputs given by you to the street address, city, country or something else like that.

How to look up ZIP/Postal Code by City using Google Maps API?

How can I extract a Postal Code or ZIP of a place by giving Google Maps a city on the map?
Basically I'm looking for a free verification service for checking completed addresses for accurate details.
I seem to remember the maps API can somehow provide a geographical point when given an address. Now I'm searching for a slightly reversed situation in order to validate the postal code typed in with a city.
You need to Geocode the address to get best match coordinates
and then Reverse Geocode the coordinates to compare zip.