gpt4 book ai didi

android - Google Places API 请求调用

转载 作者:行者123 更新时间:2023-11-29 00:46:22 24 4
gpt4 key购买 nike

我一整天都在为此苦苦挣扎

我想对 Google Places 进行 API 调用,但我似乎无法弄明白。我试过这个:http://blog.brianbuikema.com/2010/08/android-development-part-1-using-googles-places-api-to-develop-compelling-location-based-mobile-applications/

现在我有这样一个字符串:

http://maps.google.com/maps/api/place/search/xml?location=40.717859,-73.9577937&radius=1600&client=clientId&sensor=true_or_false&signature=SIGNATURE

我将 clientID 作为我的 gmail 帐户上的 Places API 的客户端 ID 以及由 UrlSinger 的方法 signRequest 填充的签名

现在如何取回 XML 或 JSON 对象?我是否需要创建一个 HttpRequest 或一个 HttpPost (或完全不同的东西)?我对此完全陌生。我想要一些示例代码。

提前致谢

最佳答案

又是一天的挣扎,我用手掌捂住了自己。

解决方案:为什么我需要那个签名?

像这样的链接工作得很好:

https://maps.googleapis.com/maps/api/place/search/json?location=50.936364,5.873566&radius=500&name=ziekenhuis&sensor=false&key=FILL_IN_KEY_HERE

正在通过此方法检索 JSON 对象

private JSONObject executeHttpGet(String uri) throws Exception{
HttpGet req = new HttpGet(uri);

HttpClient client = new DefaultHttpClient();
HttpResponse resLogin = client.execute(req);
BufferedReader r = new BufferedReader(
new InputStreamReader(resLogin.getEntity()
.getContent()));
StringBuilder sb = new StringBuilder();
String s = null;
while ((s = r.readLine()) != null) {
sb.append(s);
}

我在这里找到的(在帖子的底部):

http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/

该方法显然需要一些重写,但它有效。

关于android - Google Places API 请求调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6163318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com