Restrict google autocomplete to one country when using no libraries - google-maps

I am making the autocomplete API request like this.
https://maps.googleapis.com/maps/api/place/queryautocomplete/json&key=mykey&input=ko
This is working fine. But how can we restrict the results to one country?
I tried to pass in country restriction using components as mentioned in docs like below.
https://maps.googleapis.com/maps/api/place/queryautocomplete/json&key=mykey&input=ko&components=country:fr . But it's still returning all countries. Could someone tell me the correct way to do this?

Components are available for the Place Autocomplete method (https://developers.google.com/maps/documentation/places/web-service/autocomplete) but not for the Query Autocomplete method (https://developers.google.com/maps/documentation/places/web-service/query).
The parameter you are providing is getting ignored.

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.

How do I do column contains with API

With the GUI I can do a filter on a column for contains. The API does not seem to allow that. Is there anyway to do this with the api?
What I think you're looking for is the like SoQL function, which is available on Text. You'll need to make sure you're using the latest version of your dataset's API, and you can find instructions on how to locate that in the developer portal's changelog.
For example:
https://open.whitehouse.gov/resource/9j92-xfdk.json?$where=position_title like '%25ASSISTANT%25'

Locating current Google Place i'm at by latitude/longitude via Google Places API

i have a lat/long location data and i need to get current Google Place where i'm at now.
For example, if i'm in a shop(cafe, gym, etc..), i need to get info about THAT particular shop(cafe, gym, etc..).Or at least the closest one.
So, i'm doing it this way:
First i fetch place basic info(placeid,name, etc.) via Google Places API Nearby Search request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.7597351,-73.9836576&radius=16.66&key=...
Then i find the closest one(which is apparently where i am) and perform Place Details request with it's placeid
So, everything works fine, except for some places like the one located at 40.7597351,-73.983657 (New York Guitar lab shop) which i can see on google map, but can't get in my response. Even places that are further from my location than this, are being found fine.
I've already tried to use rankBy=distance and then checking if the result is in required radius manually, still no use. Actually, maybe this approach is right, but as told in the docs, it's required to use types parameter with rankBy=distance. So, i set types=establishment since i actually need everything except addresses and locality tokens returned. I think that the problem is some places i need, are neither counted as establishments nor as localities, but i don't know the optimal way to exclude
all types specified at (https://developers.google.com/places/documentation/supported_types) Table 2 from my response. Is there a way to get only places which types are in Table 1 (except for specifying them ALL in my types param, haha)
So, could you please help me with how can i do this?
Thanks:)
P.S. here is very similar but unaswered question
Google Places API Displaying Inaccurate Result
It seems that there's explanation here (https://developers.google.com/places/faq#why_are_some_places_never_returned_even_though_they_have_google_pages). Looks like some places are just not yet verified by Google.
And yes, the establishment is the generic category for all non-localities. So you can be sure that if you set type=establishment then you'll have as much places as you will, if you'll specify all types from Table 2. Good Luck!

Is there an OR operator on google place API?

I am using this api call with &keyword= and I want to have multiple words in the keyword but OR them. I have tried OR and | but it seems to ignore it. example here
Is it possible to OR keyword in a google places search
The Google Places API does not current support multiple keywords or names in requests. A Places API - Feature Request for this has been filed here.
If you believe this would be a useful feature please make sure your star the request to let us know you are interested in seeing it added.

Missing formatted_phone_number field in Google Places autocomplete API's getPlace Details response

I am trying to use Google places autocomplete API for one of my application.
It works allright. But, I dont get the key formatted_phone_number in the result for the place detail request.
This is what I've been trying:
Step1: Call to autocomplete api with keyword "Mike's chili" as below:
https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=Mike%27s%20chili&types=establishment&sensor=false&key=AIzaSyC2L1pPVbgCXUFuobrHS6vjN1RPbjibaME
Step2: Use the reference key in the first result of above request and make call to google Places Detail api as below:
https://maps.googleapis.com/maps/api/place/details/xml?reference=CmReAAAAtR79EFJeGGLjMflCzFh_n5Rl4rEJfU_dg-zs-1ZyPVHQQmMneLO2P0J4APa3dpV2YvscqbyOK50iARnevHcUOnRvAc33hDGQQAPWxJbzSTw0GF3nDOXP1R7Zep68Yc37EhAmWbhrqVT3Ht-SffUHi1jgGhR81n4FV2ywKBkmbS8_4MrsI85w8w&sensor=false&key=AIzaSyC2L1pPVbgCXUFuobrHS6vjN1RPbjibaME
But, I dont get the field called formatted_phone_number in return. This happens for some of the other results also.
When I search for the same in Google maps, I get the phone number.
Can someone please help me on this?