gpt4 book ai didi

android - 如何在 Android 中访问 Google Places API?

转载 作者:太空狗 更新时间:2023-10-29 14:29:51 26 4
gpt4 key购买 nike

我正在开发一个使用 google places API 的应用程序。

我为我的应用程序获得了 API key ,但问题是我从服务器得到的响应是 ZERO_RESULTS

这是我使用 DefaultHttpClient 建立 http 连接的代码。谁能告诉我问题出在哪里?请帮助我被困在这里。

public class Splash extends Activity{
private String keystring="";
//This is my request url
String requesturl="https://maps.googleapis.com/maps/api/place/search/json?" +
"location=17.739290150000002,83.3071201&radius=6000&" +
"types=hospital&sensor=false&key=";
private static byte[] key;
String signaturegot;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
/*
Here I am using default http client to establish
the connection for the request url
*/

HttpClient client=new DefaultHttpClient();
StringBuilder builder=new StringBuilder(requesturl);
builder.append(URLEncoder.encode(keystring));
HttpPost post=new HttpPost(requesturl);
try {
HttpResponse response=client.execute(post);
HttpEntity entity=response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
String val = StaticUtils.convertStreamToString(is);
Log.e("",val);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}



Here is the response from the server
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}

最佳答案

由于一些奇怪的原因,对于印度的位置,使用 names 而不是 types

https://maps.googleapis.com/maps/api/place/search/xml?&location=17.739290150000002,83.3071201&radius=6000&names=hospital&sensor=true&key=yourkeyhere

对于电话号码,您必须使用从上述 URL 获得的引用字符串请求详细信息:

https://maps.googleapis.com/maps/api/place/details/json?&reference=usethereferencestringfromtheaboveurl&sensor=true&key=yourkeyhere

输出将包含:

"formatted_phone_number" : "0891 123 0101",
"geometry" : {
"location" : {
"lat" : 17.7060120,
"lng" : 83.3104410
}
},

关于android - 如何在 Android 中访问 Google Places API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8062936/

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