13

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.

Kara
  • 5,650
  • 15
  • 48
  • 55
Jamie Hutber
  • 22,870
  • 34
  • 131
  • 236

2 Answers2

17

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

Asim
  • 6,092
  • 7
  • 32
  • 58
Rob van den Berg
  • 770
  • 5
  • 21
2

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.

Marcel Alves
  • 367
  • 1
  • 3
  • 12