Skip to content Skip to sidebar Skip to footer

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 comin

Solution 1:

You can parse it by Json.

if you see your url contains xmlhere . 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
{
    HttpPosthttppost=newHttpPost("https://maps.googleapis.com/maps/api/place/search/json?&location=17.739290150000002,83.3071201&radius=6000&names=hospital&sensor=true&key=yourkeyhere");
    HttpClienthttpclient=newDefaultHttpClient();
    response = httpclient.execute(httppost);
    Stringdata= EntityUtils.toString(response.getEntity());
    System.out.println(data);
    //parse with Json, Gson, Jackson

} catch (Exception e) {
    e.printStackTrace();
}

Post a Comment for "How To Use Google Places Api In Android?"