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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With