Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps places API to only return cities?

I am trying to use Google's map API to only return cities from their json request:

 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=green%20lanes&types=geocode&sensor=false&types=regions&key=*API KEY HERE*

The key being &types=regions but it still returns all results.

For example, I am searching for the street Green Lanes and rather than returning cities that might contain Green Lanes its returning the street in London as the top result.

like image 312
Jamie Hutber Avatar asked Apr 21 '13 15:04

Jamie Hutber


People also ask

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.

Can you customize Google Maps API?

Create a map with the Google Maps API.Google Maps Platform gives you the ability to create a truly custom map that works exactly how you want it to.


2 Answers

This is an old question, but the accepted answer is not correct for the specific question.

The correct argument for the types parameter to return only cities is (cities). So the complete URL would be:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=green%20lanes&types=(cities)&key= API_KEY_HERE

You can see more information here. Also, I omitted the sensor parameter since it's not needed anymore.

like image 175
Marcel Alves Avatar answered Oct 21 '22 08:10

Marcel Alves


https://maps.googleapis.com/maps/api/place/autocomplete/json?input=green%20lanes&types=geocode&sensor=false&types=regions&key=API KEY HERE

should be

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=green%20lanes&sensor=false&types=(regions)&key=API KEY HERE

ZERO RESULTS, because regions does not search for street name:

the (regions) type collection instructs the Place service to return any result matching the following types: locality sublocality postal_code country administrative_area1 administrative_area2

like image 18
Rob van den Berg Avatar answered Oct 21 '22 10:10

Rob van den Berg