Google Map API for addesses search - google-maps

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.

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 places and geocode not returning full results list

I am doing some mapping work and need to find latitude and longitude of villages in india many of which are small and rural. I am having trouble finding the full set of locations with the same name, for example a village named 'Kallanai' (see api links below, note they need appropriate keys for the places API to run on your computer). I can find the one I'm looking for in google maps by entering www.google.co.in/maps/place/Kallanai into the browser however it will not turn up in the geocoder or places api without specifying the associated pin code (analogous to zip-code). Can anyone explain why the basic searches for either the geocode or places API using the village name alone do not return the village with the pincode 625501 in the results?
e.g.
Google places:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai&sensor=false&key=enter your key
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai+625501&sensor=false&key=enter your key
will post google geocode links in follow up as stackoverflow will not let me include more than 2 links in my post without more points.
In a world where autocomplete is common and almost taken for granted, Google Maps has (long) switched to showing just the one results your most likely looking for.
Places Autocomplete API might get you more of what you're looking for, but it would still be a sub-optimal fit for database-like queries like this. It works best when you have users typing, each of them knowing which Kallanai they want, so they can select the suggestion that matches, and they can add details (e.g. PIN code) to get it if the suggestion doesn't show up at first (max 5 suggestion show each time).
Google does Geocoding in a different way from classic GIS databases. To obtain all cities [with a given name] in a given country, you'd probably need a database like GeoNames or Natural Earth.

how to get the complete address(es) using a business name?

I know that google maps's JSON return includes a "formatted_address" that gives you the full readable address but I've tested it on a couple of places with no success, the lat and lng coordinates aren't correct either. If I manually search it using maps.google.com it would be correct so I know the input is specific enough. How can I use the API to do this? What if the input is vague? Can I get a JSON return that includes all possible locations? (i.e. McDonalds in NYC will surely return many coordinates)
example:
http://maps.googleapis.com/maps/api/geocode/json?address=time+square+nyc&sensor=false
this returns the CORRECT coodrinates and full address that I can use.
http://maps.googleapis.com/maps/api/geocode/json?address=amc+loews+boston&sensor=false
this does not. but of course if i just search "amc lowes boston" manually it returns the correct address on google maps.
I think you're looking for Google Maps' Places Library.

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.

Geo input - how to input, store and display locations

I would like to store a user enter location and could do with some pointers on how to go about it.
Input - I wish to allow the user to enter a location using either a map (eg Google maps) or text input.
Storage - I believe it would make sense to store the location as the longitude and latitude.
Manipulation and Display - I'd like to display a name for a given longitude and latitude. I'd also like to search for all inputs from an arbitrary region eg London.
What libraries or packages (preferably Java, preferably free) can be used to help with this process?
The process of converting an address to a latitude/longitude pair is called geocoding. Doing the reverse process (lat/long to address) is called reverse geocoding.
The Google Maps API is capable of performing both these functions. However, note that there are service limits in place on the number and frequency of requests made to perform these functions. This means you'll want to implement some kind of caching mechanism for the results.
Doing a name search for a region I don't know about. The maps API may do this, but I haven't gone in enough depth with it to find out.