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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With