Select Google place detail fields - google-maps

I'm using the Google Places API to get details about certain places.
I would like to be able to limit the number of fields returned by the detail of a place. For example, get the Google Places API to return only the name, phone number and location of a place.
I read this article from the documentation but, it does not talk about it:
https://developers.google.com/places/web-service/details?hl=es-419
Any ideas ?

The ability to define which fields should be available in the response of Places API web service will become effective today, June 11 2018 or within next days.
I can see that you are checking Spanish version of documentation. Usually localized translations of Google Maps documentation are outdated. I would suggest always checking only English version. However, as I can see Google didn't update English version yet. I would expect an updated documentation within a couple of days.
In the meantime you can find explanations regarding fields in the user guide related to the transition to Google Maps Platform.
https://cloud.google.com/maps-platform/user-guide/product-changes/#frequently-asked-questions
According to the user guide,
Places Details requests will be updated to return only the fields that you specify. Currently when you make a Places Details request, the API returns all of the available data associated with the specified place. With this change, the response is limited to only those fields specified using the fields parameter.
The fields correspond to Places Details results, and are divided into three billing categories: Basic, Contact, and Atmosphere. The cost for each request varies depending on which fields are selected;
The Basic category does not result in any additional charge and includes the following fields:
place_id, name, type, address_components, formatted_address, url, utc_offset, permanently_closed, geometry.location, geometry.viewport, photo.photo_reference, icon, types, adr_address, scope, vicinity
The Contact category results in an additional charge and includes the following fields:
opening_hours.weekday_text, opening_hours.open_now, opening_hours.period, website, formatted_phone_number, international_phone_number
The Atmosphere category results in an additional charge and includes the following fields:
price_level, rating, reviews
Based on this documentation you should create the following request
https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=name,formatted_phone_number,geometry.location&key=YOUR_API_KEY
I've just tried this request, but it looks like Google didn't switch on fields filter yet. I'm getting all fields in the response. I believe it just matter of days to see this functionality in action.
I hope this helps!

Related

Google Place Autocomplete API showing invalid address

We are currently trying the Google places autocomplete api, but it seems as though Google places autocomplete api also returns invalid (non existent) addresses in the search result.
We want to receive only valid / actual addresses when the user types in the address autocomplete, is there a way to do it?
I searched the api docs but couldn't find anything much helpful.
There is a google places validation api but it only validates after given a single address, but we want to show only valid/actual addresses on search autocomplete and also don't want to call validation api for each of the search result items.
Went through official doc and also experimented several stackoverflow answers but those didn't match our requirements.
SO ref-1
This is Working as Intended as of now
I tried reproducing the Autocomplete request using this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=address&key=API_KEY
And the results returned has a long Place ID.
According to the Places API documentation:
"Place IDs uniquely identify a place in the Google Places database and on Google Maps."
The documentation also says that the API may return a different place ID in the response. These place ID types include:
Street addresses that do not exist in Google Maps as precise addresses, but are inferred from a range of addresses.
Segments of a long route, where the request also specifies a city or locality.
Intersections.
Places with an address component of type subpremise.
These IDs often take the form of a long string.
This explains why the API still returned a street address for the input =332 Kennedy drive, Torrington, CT using types=address. The use case of autocomplete is to help the users obtain the closest result even if they are requesting an ambiguous query. So the Autocomplete always tries to return the closest result to their input and types. In your case, it returned a street addresses that do not exist in Google Maps as precise addresses, but are inferred from a range of addresses.
There's a public bug on the issue tracker that is somehow related to this. On the comment #5, it says that:
Suggestions are sometimes created for addresses that may not exist, if there are chances that they do.
Retrieving details for such suggestions may result in the suggested address, if it actually exists or can be synthesized from existing data. Otherwise, the result may be a different address, one that actually exists.
Possible workaround
One thing you can do is to use the validation API.
But since you mentioned that you don't want to use it, I tried the Autocomplete request using this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=establishment&key=API_KEY
I just changed the types=address to types=establishment and it seems to return legit addresses. I'm not sure if this would fit on your use case, so you can just comment down if it does not.
And if it does not, I found a similar public bug on the issue tracker which says that similar issues like these are currently being worked on by the Google engineers internally. So what I would advise you to do wait for on update from this public bug.
There's no definite timeline on how long this will be fixed, but you can star it to be notified whenever there's an update.
Hope this helps!
== UPDATE ==
I tried playing around with the types and got to a point where I tried putting an array of types from this table. I tried this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=332%20Kennedy%20drive,%20Torrington,%20CT&types=street_address|street_number|premise&key=API_KEY
and it did return some real addresses. I changed the types=address to types=street_address|street_number|premise. You could try it out yourself and play around with the types and see if it works for your use case.
for more information about types, here's a link to the documentation.

Google Place Details does not return photos array

I am sorry if this question has an answer somewhere, I have searched and did not find any answer and I don't know what to do anymore.
I am developing an Ionic3 application and I am trying to search for a place on Google maps and then retrieve photos related to that place using Google Place details API. But photos are not returned. I have tried multiple combinations, even tried other places. Some other fields are returned but just not photos.
This is how I tried to retrieve :
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&fields=photo,name,rating,formatted_phone_number&key=YOUR_API_KEY
and I tried getting details via :
http.get(" https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&fields=photo,name,rating,formatted_phone_number&key=YOUR_API_KEY")
.subscribe((data)=>{
console.log(data)
});
I replaced the place id and API KEY with mine. But no photo is returned.
Some of the fields inputted are returned but not photos.
What is the best way to retrieve photos?
I feel this might be relevant for someone in this situation too. Going through the documentation again, I realized that Places API does not return photos for other types other than the following types: establishments, geographic locations, or prominent points of interest. Most of my place search types were routes so it didn't return photos. But when the types were changed to match the allowed ones, photos were returned.
For example, Places does not return photos of a particular street except if it is a prominent point of interest as indicated above.
To get photos of street, Street View API might be the better option.
in Place Details API (https://developers.google.com/places/web-service/details) will result you will get photo_reference and inside you will find photos[] array
Now the place photo service is apart of the places API
then use Place Photo Requests to get the photo.
have a look in below url for service call
https://maps.googleapis.com/maps/api/place/photo?photoreference=PHOTO_REFERENCE&sensor=false&maxheight=MAX_HEIGHT&maxwidth=MAX_WIDTH&key=YOUR_API_KEY
Refrence: (https://developers.google.com/places/web-service/photos)

Can users rate a restaurant by using google places API?

I am able to get restaurants list, timings, rating and displaying them in my Android application by using Google places API. This is API
https://maps.googleapis.com/maps/api/place/search/json?location=13.0104611,80.2086226&
radius=10000&types=cafe|restaurant&hasNextPage=true&nextPage()=true&sensor=false&key=MY_API_KEY
As per my client requirement, Users should be able to give rating to a specific restaurant from my application, this restaurant got from above Googel API.
Kindly tell me whether possible or not giving rating to a restaurant from above API . Thanks in advance.
According to the documentation, using the Google Places API Web Service, the following place requests are available:
Place Searches return a list of places based on a user's location or search string.
Place Details requests return more detailed information about a specific Place, including user reviews.
Place Add allow you to supplement the data in Google's Places database with data from your application.
Place Photos gives you access to the millions of Place related photos stored in Google's Place database.
Place Autocomplete can be used to automatically fill in the name and/or address of a place as you type.
Query Autocomplete can be used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
The only request that allows to put data is Place Add, but according to the documentation it adds a place that is available immediately in Nearby Searches initiated by your application and also enters a moderation queue to be considered for Google Maps.
So the answer is that for the time being it's not possible to add reviews to Places using the Google Places API Web Service.

Google maps api and cross locale city search

i have a website where people can buy/sell services in different cities.
I use google maps api v3, autocomplete and searchbox elements, to let them choose a city, store it in the db, and search against the db when they're buying.
Problem is, google searches are localized, so when a user looks for the same city in a different locale they won't find any match in my DB.
My solution would be to map each city to a code (much like yahoo's WOEID) and store that into my db, this way cross locale search would be ok, but i couldn't find anything like it in google maps api reference.
So, is there a way to keep using google maps, do i have to switch to yahoo, or is there another solution to cross locale searches i'm not aware of??
Thank you
Dario
If using the Places library, a search returns a PlaceResult object that has two properties that can help you:
id contains a unique identifier denoting this place. This identifier may not be used to retrieve information about this place, but can be used to consolidate data about this Place, and to verify the identity of a Place across separate searches. As ids can occasionally change, it's recommended that the stored id for a Place be compared with the id returned in later Details requests for the same Place, and updated if necessary.
reference contains a token that can be used to query the Details service in future. This token may differ from the reference used in the request to the Details service. It is recommended that stored references for Places be regularly updated. Although this token uniquely identifies the Place, the converse is not true: a Place may have many valid reference tokens.
Documentation reference
Edit:
Note: The id and reference fields are deprecated as of June 24, 2014. They are replaced by the new place ID, a unique identifier that can be used to reference specific places. The Places service in the Google Maps JavaScript API currently returns a place_id in all responses, and accepts a placeId in the Place Details request. Soon after June 24, 2015, the service will stop returning the id and reference fields in responses. Some time later, the service will no longer accept the reference in requests. We recommend that you update your code to use the new place ID instead of id and reference as soon as possible.

Google Places Autocomplete API flow

I want to use Google Places Autocomplete API to provide search-while-typing for an Android app.
the Autocomplete API returns IDs and References, requiring an iteration through the results to get the details (such as name and geometry) for each place, this is slow and results in a bad user experience. also, many API calls are done for each key press.
is there a better way to provide such searching capability with Google Places ?
Is there a reason you need to have the geometry for each possible autocomplete place after each keypress of the API? Showing this seems like generally it would not be a great user experience, and is not what the Autocomplete API was designed for.
In theory the name (description) should be enough for the user to decide which item they're interested in, and then after a user has actually selected something you can request additional details as needed.
On the other hand if you already have some information about the name of the place, you could use the Places API (not Autocomplete) to get additional details of matching nearby places:
https://developers.google.com/maps/documentation/places/#PlaceSearchResponses