Google Places API Search for Keyword and City - google-places-api

I would like to allow users to search for a keyword + city to return results for that keyword in a city.
For example "starbucks Seattle" should return all starbucks in Seattle.
However, it doesn't seem that keyword search includes cities - and so "starbucks seattle" just returns nothing.
I think the autocomplete api has such functionality, but the places api does not.
Any suggestions?

Try using the Places API Textsearch endpoint:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=starbucks+seattle&sensor=false&key=YOUR_API_KEY

Related

Find Place requests Returns Only One Result

I'm using the Google Places API endpoint "findplacefromtext" and tried a search similar to the example.
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=mongolian%20grill&inputtype=textquery&fields=photos,formatted_address,name,opening_hours,rating&locationbias=circle:2000#47.6918452,-122.2226413&key=YOUR_API_KEY
However, when you use this it only ever returns one result. There is a cafe near me that's called "Cream" but when you pass that as the "input" parameter it returns shops that have a category of "Ice Cream". I thought it should only search the name of the business.... If I can't find the place by name does it search the category type as a fall back? When I execute the same search in Google Maps it returns the same data but I get multiple results and I can see the place I am trying to retrieve 3rd on the search result list.
Is it possible to make it return more than one result? The documentation doesn't mention anything about this.
I believe what you need is the Text Search request. The Find Place request is meant for exact addresses.
The Google Places API Text Search Service is a web service that
returns information about a set of places based on a string — for
example "pizza in New York" or "shoe stores near Ottawa" or "123 Main
Street". The service responds with a list of places matching the text
string and any location bias that has been set.
The service is especially useful for making ambiguous address queries
in an automated system, and non-address components of the string may
match businesses as well as addresses. Examples of ambiguous address
queries are incomplete addresses, poorly formatted addresses, or a
request that includes non-address components such as business names.
Taken from https://developers.google.com/maps/documentation/places/web-service/search#TextSearchRequests

Google Place Autocomplete API not returning latest city name

I'm making use of google's Place Autocomplete API to get list of cities,
https://developers.google.com/places/web-service/autocomplete.
Problem is when I search "Bombay", it should return the new city name
"Mumbai". Same for "Calcutta" instead "Kolkata" and "Madras" to "Chennai".
Google Place Search api returns all the right renamed city names but unfortunately it's not for autocomplete use.
In Text search API you will get new names :
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=YOUR_KEY&types=city&query=Bombay
So If you can use above API you can use.
In autocomplete add types=(cities) but it returning old names only, I think google data is not updated.
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=YOUR_KEY&types=(cities)&input=Bombay
I think the fool proof solution for this is to use Google place autocomplete and get a list of predictions. Then use the first prediction's place_id as an input for Google Place details
Step 1
Step 2

Google Places Autocomplete to return non-abbreviated administrative areas?

Running the HTTP request: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=atlanta&types=(cities)&sensor=false&key=<api_key>
returns results that include Atlanta, GA, United States
Is there a way to return results of a query that don't includes abbreviated names? So I could get back Atlanta, Georgia, United States?
Or do I need need to make an additional query with the reference token?
Try using Google Place Details API with the "reference" parameter returned by Google Place Auto Complete. This will return extensive information on your location query, including long and short names.
https://maps.googleapis.com/maps/api/place/details/json?reference=x&key=y&sensor=false
where x is the "reference" from your auto complete query, and y = your API key.
Here is the link for the Details API:
https://developers.google.com/places/documentation/details#PlaceDetailsRequests

How to get Country for Google Places API nearby search

I'm using Google Places API to get nearby places, but I've noticed that while I get the place names and addresses, the results don't include the Country.
Is there a way to get the country included in the results?
This is the call I'm using:
https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=<lat,lng>&radius=100&sensor=true&key=<api_key>
Thanks!
The Geocoding API is what you want.
Try
http://maps.googleapis.com/maps/api/geocode/json?address=Calgary,%20Alberta&sensor=false
it'll return fully formatted address info in several ways (split by administrative level, formatted as an address,etc.)
also the place Types blog in google api will help..link is here

How to sort results by distance with google places api using textsearch

I want to get all the restaurants near my location order by distance.
I am using textsearch with google places api using this url : https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants&location=32.16107,34.806618&radius=200&sensor=true&key=api_key. The results that I am getting are sparse with no order what so ever. I tried rankby=distance but accurding to the documentation (https://developers.google.com/places/documentation/) you can use it only with regular search,means that when using textsearch there is no such parameter option (I tried it anyway -> not working).
I am using textsearch because regular search returns only "types" : [ "establishment" ].
How can I order by distance the textsearch of google place api ? I can't believe that google didn't create a way to do it...
You are correct, Places API Textsearch does not support the rankBy=distance parameter. If you believe that this would be a useful feature, please submit a Places API Feature Request.
You can however obtain the result you are looking for by performing a Places API Search Request using the rankBy=distance parameter and the keyword=restaurant parameter:
https://maps.googleapis.com/maps/api/place/search/json?keyword=restaurant&location=32.16107,34.806618&rankBy=distance&sensor=false&key=YOUR_API_KEY
The keyword parameter is matched against all available fields, including but not limited to name, type, and address, as well as customer reviews and other third-party content.

Resources