Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places API search by city again

I want to search all cafe and restaurants in New York. Of course, I can use Text Search, as it recommended here - Google Places API Search for Keyword and City

But if I do a request like https://maps.googleapis.com/maps/api/place/textsearch/json?query=cafe+New+York+food&sensor=false&key=MY_KEY

First element, which I got, is

"formatted_address" : "316 Victoria Avenue, Chatswood NSW, Australia",

really no way to filter data by city? This data exists in address, why no good way to filter by city, only via keywords?

like image 804
Oleg Sh Avatar asked Sep 05 '13 19:09

Oleg Sh


People also ask

How do I restrict google places to a specific city?

Just add prefix with city name in request. Hi, is there any way to do the same functionality without displaying the prefix. To do this, you need get result of search request from google and render your own autocomplete widget.

How do I use google places API for location analysis and more?

Get your Places API key and add it to your request To get your API key, you need to perform following actions: Open Google Cloud Platform Console. Click on the project drop-down list and pick the project created for you. Its name should start with Google Maps APIs for Business or Google Maps for Work or Google Maps.

How do you refresh a place id?

You can refresh Place IDs at no charge, by making a Place Details request, specifying only the place_id field in the fields parameter. This will trigger the Places Details - ID Refresh SKU. However, this request might also return NOT_FOUND status code.

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.


1 Answers

You can add a location parameter to your query (requires also to specify the radius).

so your query would look like :

https://maps.googleapis.com/maps/api/place/textsearch/json?query=cafe+New+York+food&sensor=false&location=40.67,-73.94&radius=100&key=YOUR_KEY

see the full documentation here : https://developers.google.com/places/documentation/search#TextSearchRequests

like image 66
yonili Avatar answered Sep 29 '22 10:09

yonili