我使用谷歌地图在两个位置之间得到了一条折线,当我想通过使用 Json 解析使用此 URL 来获取这两个位置之间的路线和方向时 https://maps.googleapis.com/maps/api/directions/json?origin=fromlocation&destination=destinationlocation&sensor=false&key= ********API key ************ 它得到的 json 解析为 { "error_message": "此 IP、站点或移动应用程序无权使用此 API key 。", “路线”:[], “状态”:“REQUEST_DENIED” } 我已经使用 keytool 以及包名称和指纹 key 获得了授权的 APIKEY
这是我所做的代码,提前感谢我的英语...
私有(private)类 GetContacts 扩展 AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(DirectionActivity2.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
String URL="https://maps.googleapis.com/maps/api/directions/json?origin=start&destination=end&sensor=false&key=****API KEY*****";
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
最佳答案
2019 年 6 月 28 日更新:
以前,Google 曾经允许在没有 api key 的情况下调用方向、地理位置 api,最高可达 certain extent 。这是一个方便的开发功能,因为您只需更改浏览器中的 url 即可。他们更新了政策。
现在您需要提供有效的 API key 。更多信息请参见以下link .
上一个答案:
尝试删除 API key 。我使用了它,它返回了一个有效的 json。
关于android - 此 IP、站点或移动应用程序无权使用此 API key 。在 Android 谷歌地图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23722885/