【问题标题】:How to use Google Places API in Android?如何在 Android 中使用 Google Places API?
【发布时间】:2012-06-05 05:59:29
【问题描述】:

我知道访问 google 地方的 URL。 check here

但我无法解析来自 XML 格式的 URL 的数据。所以,告诉我以 xml 格式显示来自 google 地方 API 的数据的机制。

请告诉我一些示例代码或任何教程。

提前致谢

【问题讨论】:

  • 您到底想要什么?从 XML 解析中得到了什么??
  • 用 google api 键点击 URL 就知道返回了什么。
  • 它正在返回<PlaceSearchResponse> <status>REQUEST_DENIED</status> </PlaceSearchResponse> 请在此处出示您的密钥
  • stackoverflow.com/questions/7344581/… 听说你可以得到如何在android中使用place api的代码。

标签: android xml parsing google-places-api


【解决方案1】:

你可以通过Json来解析它。

如果您看到您的网址包含 xml here这将在 xml 中给出响应。

使用 xml 输出:

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

只需将其替换为 json 就像 this这将在 Json 中给出响应。

使用 Json 输出:

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

请参阅this-blog 以获取更多帮助

用于解析

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

【讨论】:

  • 在那之后下一步该做什么。我的意思是,我正在从 Json 获取数据。现在,如何以正确的格式显示它。实际上,我对 Android 还是很陌生。
  • @hotveryspicy,我将在我的应用程序中实现很好的补偿。
  • 数据是字符串(保存响应)。
【解决方案2】:

首先到这里。 Link 然后是有关 google 地方的其他信息。

Google Places API 是一项返回有关 Places 信息的服务 — 在此 API 中定义为机构、地理位置、 或突出的兴趣点——使用 HTTP 请求。提出请求 将位置指定为纬度/经度坐标。

四个基本的地方请求可用:

  • Place Searches 根据用户的位置返回附近地点的列表。
  • Place Details requests 返回有关特定地点的更多详细信息。
  • Place Check-ins 允许您报告用户已签到地点。签到 用于衡量某个地方的受欢迎程度;频繁签到将提高 地点在您应用的地点搜索结果中的排名。
  • Place Reports 允许您向 Place 服务添加新的 Places,并删除 您的应用添加的地点。

Places API 还支持定义为任何类型的事件 发生在某地的公共或私人聚会、表演或促销活动 地点服务中列出的位置。有关详细信息,请参阅 Events in the Places API

More)。这是how to use google places in android 的最佳教程。

并转到此链接Google’s Places API to Develop Compelling Location Based Mobile Applications 另一个谷歌地图示例(here)。 Video 为谷歌地方的谷歌开发者。

我认为这可能对您有所帮助。

【讨论】:

    猜你喜欢
    • 2011-04-19
    • 2016-05-13
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多