我正在开发一个应用程序,我必须获取当前位置附近的所有位置名称(纬度/经度),并且所有位置都应在1000米半径范围内。
目前我正在使用以下API网址:
我每次都会得到回复:
{
"debug_info" : [],
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
我的代码:
private String makeUrl(double latitude, double longitude,String place)
{
StringBuilder urlString = new StringBuilder("https://maps.googleapis.com/maps/api/place /search/json?");
if (place.equals("")) {
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
urlString.append("&radius=1000");
//urlString.append("&types="+place);
urlString.append("&sensor=false&key=" + API_KEY);
} else {
urlString.append("&location=");
urlString.append(Double.toString(latitude));
urlString.append(",");
urlString.append(Double.toString(longitude));
urlString.append("&radius=1000");
//urlString.append("&types="+place);
urlString.append("&sensor=false&key=" + API_KEY);
}
return urlString.toString();
}
private String getUrlContents(String theUrl)
{
StringBuilder content = new StringBuilder();
try {
URL url = new URL(theUrl);
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()), 8);
String line;
while ((line = bufferedReader.readLine()) != null)
{
content.append(line + "\n");
}
bufferedReader.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return content.toString();
}
答案 0 :(得分:1)
REQUEST_DENIED
表示您使用了错误的密钥。启用Places API
,然后尝试。
启用Browser Key
Places API
答案 1 :(得分:1)
{
"debug_info" : [],
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
它说你使用了错误的密钥 请参阅https://developers.google.com/maps/documentation/javascript/tutorial?csw=1#api_key 有关如何获取新API密钥的信息,