Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API: return results for postcode

A client has requested a page with a text input which takes a postcode and returns an array of local shops in the area.

How would I achieve this with the google maps API or something similar, this is the first time I have come across such a demand and a push in the right direction would be very helpful.

Thanks, Dan

like image 837
Dan C Avatar asked Dec 02 '10 12:12

Dan C


People also ask

How do I get a postcode from Google Maps?

Open a contact or an organization with a postal address. Beside the postal address, click on the map icon. The postal address will automatically open on Google Maps.

How do I get data from Google Maps API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

How do I get a city from places API?

2) Make another web-service call to https://maps.googleapis.com/maps/api/place/details/json?key=API_KEY&placeid=place_id_retrieved_in_step_1. This will return a JSON which contains address_components . Looping through the types to find locality and postal_code can give you the city name and postal code.

What is the best way to display information about a certain location in Google Maps API?

Once you have a place_id from a Place Search, you can request more details about a particular establishment or point of interest by initiating a Place Details request.


1 Answers

I'm not entirely certain about how to do this in Google Maps completely, but you can get the details of a place (including the all important longitude and latitude) very easily through the Geocoding API.

For example: http://maps.googleapis.com/maps/api/geocode/json?address=WC1&sensor=false

Although you are able to put addresses, rather than postcodes in there. You could then use this information with your own database of places. For example, you can download the GeoNames database and use something like this answer to find the closest places in your database.

Alternatively, you can use something like the FourSquare API to get a list of places in the area. You could even use the service to pull features like the tips or who is around. When I was looking for the Geocode API, I stumbled upon the Google Places API. I haven't used it and it's in developer preview at the moment, but the documentation looks interesting at least.

You might want to just check the TOS on whatever service you use. I remember at one stage that you couldn't use the map API if you're not displaying a map on the page, etc.

like image 101
Jonathon Bolster Avatar answered Sep 26 '22 23:09

Jonathon Bolster