如何在Android中使用Google Places API? [英] How to use Google Places API in Android?

查看:197
本文介绍了如何在Android中使用Google Places API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道访问Google地方的网址. 在此处检查

I know the URL of accessing the google places. check here

但是我无法解析来自URL的XML格式的数据.因此,请告诉我以xml格式显示来自Google Places API的数据的机制.

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.

预先感谢

推荐答案

您可以通过Json对其进行解析.

You can parse it by Json.

如果看到您的网址包含xml

if you see your url contains xml here . This will give response in xml.

使用xml输出:

<PlaceSearchResponse>
<status>REQUEST_DENIED</status>
</PlaceSearchResponse>

只需将其替换为json,例如

Just replace it with json like this . This will give response in Json.

使用Json的输出:

{
   "html_attributions" : [],
   "results" : [],
   "status" : "REQUEST_DENIED"
}

请参见用于解析

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();
}

这篇关于如何在Android中使用Google Places API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆