On the request for current place I receive a list of places. Every place has an address but that address is a string so I can't get only the country name.
Could someone help me on this matter?
Country is only explicitly available when using the Place Details API, not the Places API. (https://developers.google.com/maps/documentation/places/web-service/details)
You first need to look up a place_id for the specific place you're looking for. You then use your place_id to pull details from the Details API, which includes information like:
Fully formatted address, including country
Address components
Sample reviews
Phone # and website
Operating hours
If you have read the Google Places Autocomplete doc,you must know about API properties.you can use the type as '(region)' and will return you many results (plus country).And if you look inside address_components field (it's array with dynamic length),you will see,that the last item of array is what you need.Here is a great page to read a correct doc and try examples yourself.
http://www.w3docs.com/learn-javascript/places-autocomplete.html
Related
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
This question here basically asks the same question:
Restrict Google Places Autocomplete to return addresses only
But doesn't get the right answer.
If we look at the official documentation examples they have an option to selected address type. However, on it, we can see that it will allow us to selected just streets:
Is there a way to make Places Autocomplete select real addresses only?
Since this question is quite old, the search result is now somehow different but the fact that address type returns street addresses remains the same.
And to clarify things here, the API is working as intended when it returns street addresses.
types=address seems to be quite vague and what you need to do is to be more specific if you don't want street address to be included.
Here's a table for reference on the different types of restrictions for autocomplete from the Place Types Documentation.
Table 3: Type collections supported in Place Autocomplete requests
The supported types are:
geocode instructs the Place Autocomplete service to return only geocoding results, rather than business results. Generally, you use this request to disambiguate results where the location specified may be indeterminate.
address instructs the Place Autocomplete service to return only geocoding results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address.
establishment instructs the Place Autocomplete service to return only business results.
(regions) type collection instructs the Places service to return any result matching the following types:
locality
sublocality
postal_code
country
administrative_area_level_1
administrative_area_level_2
(cities) type collection instructs the Places service to return results that match locality or administrative_area_level_3.
To further prove this, I tried using the official documentation example for testing.
I tried searching real street address with both types=address and types=geocode and they return street addresses as expected.
With address type:
With geocode type:
Then I tried the types=establishment and it did not return any street addresses.
With establishment type:
You can use any other types value apart from types=establishment like the (cities) and (regions). As long as you are specific in your restrictions, things will be working fine. You can just put some toggle on your app to change restrictions just like on the official docs example so that your end user could freely choose the restrictions. But it still depends on your use case.
Hope this helps.
I can't seem to find any information on the implications of using/not using regionCode in the YouTube v3 API, for example the search/list resource.
In the specific, if the regionCode is not specified in the call to the API, will all the videos matching the criteria be returned?
If a video is allowed only in certain regions, not specifying the regionCode in the search request, will the API return it? Or only the unrestricted videos will be returned?
Where can I find some clarification on the topic?
If you do not specify the Region Code then the API automatically determines the region based on your location. So, for example, if I queried the API on my laptop in New Zealand, then the region code would be NZ.
The API outputs the region code. In JSON it is under the tag regionCode.
Generally Region Code is not required. You will get a good matching results output without it.
The regionCode parameter instructs the API to return search results for the specified country. The parameter value is an ISO 3166-1 alpha-2 country code. (string)
I have few lat,lng of some Google Places business which I want to search and get detailed information about that place.
I was looking at Place Detail search which require reference key of particular place page.
Here is what I am doing is.
Do Place search via api key for lat,lng
https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=lat,lng&radius=50&location=lat,lng&name=placenamesensor=false&key=my key
that returns exact place page result in xml and i grab ref key of that page.
then do call
https://maps.googleapis.com/maps/api/place/details/xml?reference=RefKey&sensor=false&key=MyKey
which gives output of particular business.
Now question is on 1st step to get ref key of business what if I dont know name but just know lat,lng and wish to grab ref key of that page. What query I have to fire to reduce api calls limit?
You can find it here:
I believe this is what you are looking for
https://developers.google.com/maps/documentation/javascript/places
you need to work with places api and implement the the typeahead feature
https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests
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