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.
Related
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.
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!
Is it possible to add new place with opening hours via Google Places API Web Service?
I can't find any information about it.
https://developers.google.com/places/web-service/add-place
Thank you in advance
Sorry, no. You can't provide opening hours in Add Place requests to the Google Places API.
Depending on what you need to do, you could try adding the place manually via https://google.com/maps (click "Send feedback" then "Add a missing place").
I think it is not possible. As you can see in this document, these are the only information that you can place in the body.
accuracy — The accuracy of the location signal on which this request is based, expressed in meters.
address (recommended, to improve chances of passing moderation) — The address of the place you wish to add. If a place has a well-formatted, human-readable address, it is more likely to pass the moderation process for inclusion in the Google Maps database.
language — The language in which the place's name is being reported. See the list of supported languages and their codes. Note that we often update supported languages so this list may not be exhaustive.
location (required) — The geographical location, specified as latitude and longitude values, of the place you want to add.
name (required) — The full text name of the place. Limited to 255 characters.
phone_number (recommended, to improve chances of passing moderation) — The phone number associated with the place. If a place has a well-formatted phone number, it is more likely to pass the moderation process for inclusion in the Google Maps database.
types (required) — The category in which this place belongs. While types takes an array, only one type can currently be specified for a place. XML requests require a single <type> element. See the list of supported types for more information. If none of the supported types are a match for this place, you may specify other.
Hope this helps!
I can get place details from Google places API when I know the reference by using:
https://maps.googleapis.com/maps/api/place/details/json?reference=CmRYAAAAciqGsTRX1mXRvuXSH2ErwW-jCINE1aLiwP64MCWDN5vkXvXoQGPKldMfmdGyqWSpm7BEYCgDm-iv7Kc2PF7QA7brMAwBbAcqMr5i1f4PwTpaovIZjysCEZTry8Ez30wpEhCNCXpynextCld2EBsDkRKsGhSLayuRyFsex6JA6NPh9dyupoTH3g&sensor=true&key=API_KEY_HERE
However, I want to get the same information by using the ID instead. So the same place in the query above would be something like:
https://maps.googleapis.com/maps/api/place/details/json?id=4f89212bf76dde31f092cfc14d7506555d85b5c7&sensor=true&key=API_KEY_HERE
Is such a thing possible?
This will be part of a search filter I'm building, part of which is location. My search parameters are passed to the url, so I plan to do the same with the selected location from the places autocomplete. Using id is much shorter than reference, so more suitable for the querystring. Unless there is a better way to do it?
You can search Place data by PlaceID
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJF7QkuDsDLz4R0rJ4SsxFl9w&key=YOUR_KEY
It is now possible to fetch place data by placeId:
https://developers.google.com/maps/documentation/javascript/examples/place-details
It is not possible to get a place details with id, you do need to use the reference.
as specifically mentioned in the bottom of this link - http://goo.gl/KFDbl
Apparently both the id and reference are deprecated anyway.
From the Google Places Autocomplete Docs (Aug 2014):
"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 compare places and to retrieve information about a place. The Places API currently returns a place_id in all responses, and accepts a placeid in the Place Details and Place Delete requests. Soon after June 24, 2015, the API will stop returning the id and reference fields in responses. Some time later, the API 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. "
https://developers.google.com/places/documentation/autocomplete
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