How to use Google Places API in Android?

2019-09-02 16:37发布

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

2条回答
smile是对你的礼貌
2楼-- · 2019-09-02 17:23

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.

查看更多
Juvenile、少年°
3楼-- · 2019-09-02 17:43

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();
}
查看更多
登录 后发表回答