Google Places Autocomplete Details API - android

I am in the process of making an android application with a location field so am using Google Places Autocomplete in order to assist the user. Once they select a choice from the list, I am then getting the place_id from the response and using that to get the full address and coordinates. However, I am seeing inconsistent results. For example, if I have an address typed in I get the following in the response:
"place_id" : "ChIJhV00Saykj4ARf5pLLQUgXh8",
"reference" : "CkQ4AAAA6Oz4yvX3mdvSp_NuluEW-aMS5Kg6j0gNDxjidPUbnqsNrm17-Am4C8HwIBMfNXK20UvsrZt7MnJ1MeV3-N6kqxIQrIQn113f7ksZNBoX2NBVahoU4p6yZwFFSlTP5jZUXib5CO7uO5k",
If I use that place_id for a details request, I am missing the street_number, which was included in the previous response. If I use the reference in the details request, then I get the correct location, with the street_number along with a different place_id.
"place_id" : "ChIJm5jeVKykj4ARICvBIsIA2MI",
After reading the docs, they said reference will be depreciated and I should use place_id but it is not working properly. Does anyone know why or what is your solution for a place details request?

Related

Google directions api return zero results for some Addresses

I have studied all previous questions but did not found solution. I'm working on Google Directions API,to draw route in android. I am getting addresses from Google Places and it draws a route but there are many places where Directions returns no result.While I have checked google map and some other apps they render the same address.Then I tried the simple query in browser but the problem remains same.Help me please I am stucked here, I will be very thankful to you.Origin address is problamatic
Here is my query
https://maps.googleapis.com/maps/api/directions/json?origin=University%20of%20gujrat,gujrat,punjab,pakistan&destination=gujranwala,punjab,pakistan&key=
And the example address is "University of Gujrat, Gujrat, Punjab,Pakistan"
I am attaching browser output. Thanks in advance.
browser output
I actually tried your given query and it returned a "status" : "OK".
However, for some addresses that you got zer0_results, as discussed in Directions Response Elements, the following are the indications of values in the status field within the Directions response:
NOT_FOUND indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded.
ZERO_RESULTS indicates no route could be found between the origin and destination.
To avoid these error codes, please check parameter values that you have entered in your HTTPS Directions requests. As standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated in Request Parameters.

Missing Pin Codes in Google Maps API

I have an android app that handles logistics for me in my city (Mumbai, India). The user types in his address followed by his pin code. I use google maps API to find the (lat, long) of the area marked by the pin code and calculate which one of my stores is closest to it. That store fulfills the customer's order. So far it has been fairly successful but recently I discovered some users orders were not tended to because an error was returned on querying the pin code's location.
This is the url i send an HttpRequest to
"http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:"+uri[0]+"|country:india"
So for example if I type the link below. I get the approximate location of the vicinity marked as 400006
"http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:400006|country:india"
But If i input some pin codes such 400036, where I have been getting orders from the JSON I get returned is this
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Could someone please help me out/ explain what exactly is happening. There are a few other pin codes where I am not getting a result.

Using Google Transit APIs in android

I want to use Google Transit API in Android application. But I am getting data from service. I used the following parameters:
http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&sensor=false&departure_time=1343605500&mode=transit
I always get this response:
{
"routes" : [],
"status" : "ZERO_RESULTS"
}
I think I am passing something wrong in any of parameters used in above URL, maybe departure_time is wrong?
Can anyone tell what should pass to parameters?
Can anyone help me to find out URL with such parameters which return value ?
You just have to set departure_time parameter to some time in future (like several days). From here:
When requesting transit directions, be sure to specify either a
departure_time or arrival_time. Note that in this example the
departure time is specified as July 30, 2012 at 09:45 am. Update the
parameter to a point in the future before submitting the request.
Try http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&sensor=false&departure_time=1350472557&mode=transit, it works.

How to use Google Places API in Android?

I know the URL of accessing the google places. check here
But I am not able to parse the data coming from the URL in XML format. So, tell me the mechanism to display the data coming from google places API in xml format.
Please tell me some sample code or any tutorial for it.
Thanks in advance
You can parse it by Json.
if you see your url contains xml here . This will give response in xml.
output with xml:
<PlaceSearchResponse>
<status>REQUEST_DENIED</status>
</PlaceSearchResponse>
Just replace it with json like this . This will give response in Json.
output with Json:
{
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
see this-blog for further help
For parsing
try
{
HttpPost httppost = new HttpPost("https://maps.googleapis.com/maps/api/place/search/json?&location=17.739290150000002,83.3071201&radius=6000&names=hospital&sensor=true&key=yourkeyhere");
HttpClient httpclient = new DefaultHttpClient();
response = httpclient.execute(httppost);
String data = EntityUtils.toString(response.getEntity());
System.out.println(data);
//parse with Json, Gson, Jackson
} catch (Exception e) {
e.printStackTrace();
}
First go to this. Link then other information about google places.
The Google Places API is a service that returns information about Places
— defined within this API as establishments, geographic locations,
or prominent points of interest — using HTTP requests. Place requests
specify locations as latitude/longitude coordinates.
Four basic Place requests are available:
Place Searches
return a list of nearby Places based on a user's location.
Place Details requests
return more detailed information about a specific Place.
Place Check-ins
allow you to report that a user has checked in to a Place. Check-ins
are used to gauge a Place's popularity; frequent check-ins will boost
a Place's ranking in your application's Place Search results.
Place Reports
allow you to add new Places to the Place service, and to delete
Places that your application has added.
The Places API also offers support for events, which are defined as any type
of public or private gathering, performance, or promotion that occurs at a
location listed in the Places service. For more information, see
Events in the Places
API.
(More). Here is best tutorial for how to use google places in android.
and go to this link also Google’s Places API to Develop Compelling Location Based Mobile Applications another google map example(here). Video for google developer for google places.
I think this might be helpful for you.

Google places autocomplete api - REQUEST_DENIED

I'm creating app that use autocomplete places google api.
And I don't know what is wrong but all the time I got responses like:
{
"predictions" : [],
"status" : "REQUEST_DENIED"
}
I send req : https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Paris&types=geocode&language=fr&sensor=true&key=mykey
Documentation says :
REQUEST_DENIED indicates that your request was denied, generally because of lack of a sensor parameter.
I have sensor parameter, maybe it is something with api key.
Is there any page where can I get google's log :), to see why I got REQUEST_DENIED?
I use api key from :
http://code.google.com/intl/pl-PL/android/maps-api-signup.html
Maybe I have to get an api key from somewhere else.
You should be able to view your API Key by going to the API Console first:
https://code.google.com/apis/console
If you haven't yet, you will need to create a new "Project" and then enable the Predictions services first by using the On/Off switch.
Please post your results, I have a similar problem with getting the REQUEST_DENIED response, but I've already got the API key and I'm using the sensor parameter like their documentation states.
It is frustrating that Google doesn't give any sort of response code along with REQUEST_DENIED so you can see why it's denying it. This will be difficult to support and troubleshoot in a production environment if this randomly goes out without providing any details as to why.
Update:
I just found this works for me now, but only after changing my requests to GET requests instead of POST. For reasons unknown, Google returns REQUEST_DENIED for POST requests but allows the same request via GET. A quick test for you to see if this is your problem would be to put the URL together with your API key and other parameters and try it through your browser instead. If that works then just rewrite your Android code to use GET instead of POST and you should be all set.
It was solved for me when I exchanged the API key. I was using the one under Android device, I changed it to the one "Key for browser apps (with referers)" and it worked for me although I'm using Android Device.
I recommend using .getJson() to get an error message along with your response to know what is exactly wrong.
For my case in flutter: I used googlePlace!.autocomplete.getJson(value);
and i got the following response.
{ "error_message" : "You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable Learn more at https://developers.google.com/maps/gmp-get-started", "predictions" : [], "status" : "REQUEST_DENIED" }
That's the wrong API key. Follow the steps here to get the right one.
Make sure you API keys are generated correctly and that you have enabled the necessary APIS.
In my case, when designing iOS application - I need to enable Google Maps SDK for iOS, Google Places API for iOS
And most importantly, and without being mentioned by Google (in any other place as well) enable Google Places API Web Service.
With this, I ended a 2 day search for my pesky problem.
And, of course, make sure you use Key for server applications

Categories

Resources