Yahya Uddin
Yahya Uddin

Reputation: 28951

Use Google place autocomplete web service with Latitude & Longitude

I want to use Google place autocomplete webservice: https://developers.google.com/places/web-service/autocomplete

to search for locations based upon a query (e.g. "High Street"). I also want the latitude and longitude of each place.

It seems that the only way to do this using the web service is to:

  1. Perform an autocomplete search e.g.

    https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(cities)&language=en_GB&key=YOUR_API_KEY

  2. Loop through each result and do a separate query for each location (see https://developers.google.com/places/web-service/details):

    https://maps.googleapis.com/maps/api/place/details/json?placeid=PLACE_ID&key=YOUR_API_KEY

That means if I have 10 results, I have to do 10 additional web requests! That means 11 in total (1 for autocomplete, and 10 more for each place request).

This is very inefficient!

Surely there is a better way than this, as Google Maps on Android shows the distance of each place to your current location, indicating that the latitude and longitude is returned as shown by this screenshot:

Android Google Maps Search

Upvotes: 2

Views: 1852

Answers (2)

Franco Vizcarra
Franco Vizcarra

Reputation: 426

Yes, for Places API, Directions API and Geocoding API that is the case. There is no other way.

Upvotes: 2

Related Questions