How to find gas station using Google Places API? - google-maps

I'm looking to find gas stations around based on the location I provided. And it seems that the query string that I provide to the Google API is not really correct, leading to the desired result.
Here is the URL
https://maps.googleapis.com/maps/api/place/nearbysearch/json
And this is my query string:
?location=40.316828,%20-82.839840&radius=50000&type=gas_station&keyword=cruise&key=My_Google_Key
Response returned current>:
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}

The solution is simple, just remove the "keyword" parameter then everything will be ok. If this param is declared, the API will only return results with the same value as the param
Here is my original URL:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.316828,%20-82.839840&radius=50000&type=gas_station&keyword=cruise&key=My_Google_Key
Replace with this URL:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.316828,%20-82.839840&radius=50000&type=gas_station&key=My_Google_Key

Related

How to get the AutoComplete country list and country code list from Google places?

I am trying to run the following API call.n I am following the API DOC here - https://developers.google.com/maps/documentation/places/web-service/autocomplete#types
https://maps.googleapis.com/maps/api/place/autocomplete/json?
types=regions:country
&input=sri
&key=API_KEY
&language=en
But I am always getting the following output.
{
"predictions": [],
"status": "INVALID_REQUEST"
}
What am I doing wrong here? It is not possible to autocomplete the country list with codes?
In your request, type=regions:country is not valid. You can use type=(regions) like the docs specify:
https://developers.google.com/maps/documentation/places/web-service/autocomplete#types
This is as close as you can get to only countries.
A request like https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&input=sri&key=API_KEY&language=en will return Sri Lanka as first prediction. You could further filter your predictions by looking for only ones with "country" in the "types" field of the response.

Google Maps Find Place API locationbias causing zero results

I am trying to use the locationbias feature of the Find Place API to provide more relevant results for my searches. I have tried both a point and a rectangle, and in both cases my query returns zero results. However, if I remove the bias completely I do get a result. Why is a location that I know is within the boundary of the rectangle not being returned? Also, the field is called locationbias implying it will prefer Places near this location but not force strict boundaries, so why am I getting zero results?
Here is an example GET: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Ariel%20Dunes%201%20Unit%20308%20Seascape%20Resort&inputtype=textquery&locationbias=rectangle%3A30.119056%2C-86.527098%7C30.444872%2C-85.705723&fields=geometry%2Flocation%2Cname%2Cplace_id
Response:
{ "candidates" : [], "status" : "ZERO_RESULTS"}
Without locationbias: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?inputtype=textquery&fields=geometry%2Flocation%2Cname%2Cplace_id&input=Ariel%20Dunes%201%20Unit%20308%20Seascape%20Resort
Response:
{ "candidates" : [ { "geometry" : { "location" : { "lat" : 30.377608, "lng" : -86.366795 } }, "name" : "Ariel Dunes I (ADI) at Seascape Resort", "place_id" : "ChIJF5B7IoRbkYgRQWjAZv0-wUI" } ], "status" : "OK" }
For clarity, here's the decoded locationbias used above: rectangle:30.119056,-86.527098|30.444872,-85.705723
According to the docs this should be the southwest corner of the rectangle followed by the northeast corner of the rectangle.
The issue was due to my use of Postman. Postman implicitly encodes the query string. Disabling this feature allowed me to use a literal colon between the shape and the coordinates which corrected the behavior.

What's wrong with this Google Places (radar search) request?

I'm trying to get a list of 200 gyms in Washington, D. C. within the radius of 50000 meters.
For this purpose, I issue following request to Google Places API (radar search):
https://maps.googleapis.com/maps/api/place/radarsearch/json?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&location=38.895111,-77.036667&radius=50000.000000&sensor=false&type=gym
I get an error message:
{
"html_attributions" : [],
"results" : [],
"status" : "INVALID_REQUEST"
}
What exactly is wrong with that request?
Change type=gym to types=gym, that worked for me

What is the correct way to use the fields request parameter when getting a list of StorageObjects from Google Cloud Storage?

I would like to do a lookup in the storage using the JSON API client library and only retrieve the name and generation of each object matching a specific prefix but I am having issues with the fields request parameter.
Executing the following returns the expected objects.
Storage.Objects.List listObjects = null;
listObjects.setVersions(true);
listObjects.setPrefix(myprefix);
URL being created for the request in com.google.api.client.http.HttpRequest is https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?prefix=myprefix&versions=true
However, when I add
listObjects.setFields("name,generation");
with URL created being https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=name,generation&prefix=myprefix&versions=true the below is returned:
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "fields",
"locationType" : "parameter",
"message" : "Invalid field selection name",
"reason" : "invalidParameter"
} ],
"message" : "Invalid field selection name"
}
How am I supposed to be specifying the fields I want returned? Is the hierarchy of the fields I'm specifying not correct?
Thank you!
Ref:
Verified the composition of the URL based on this: https://developers.google.com/storage/docs/json_api/v1/how-tos/performance#partial
I think what you want is:
fields=items(generation,name)
or with the full URL:
https://www.googleapis.com/storage/v1beta2/b/mybucketname/o?fields=items(generation,name)&prefix=myprefix&versions=true
The APIs Explorer is a great tool for experimenting with request fields like this. It will generate the proper fields for you.

Google geocoding api search with Arabic language address

I am passing arabic lang search text in Google geocoding api query, but returns no result in json
string strResult="http://maps.googleapis.com/maps/api/geocode/json?address=جدة +السليمانية "&sensor=false&language=ar";
gives
{
"results" : [],
"status" : "INVALID_REQUEST"
}
kindly suggest the correctway of passing arabiclanguage search text in url.
You must encode the address-part, it should be:
http://maps.googleapis.com/maps/api/geocode/json?address=%D8%AC%D8%AF%D8%A9+%2B%D8%A7%D9%84%D8%B3%D9%84%D9%8A%D9%85%D8%A7%D9%86%D9%8A%D8%A9+%22&sensor=false&language=ar
How to encode it depends on the used programming-language