【问题标题】:This IP, site or mobile application is not authorized to use this API key. in android google maps此 IP、站点或移动应用程序无权使用此 API 密钥。在安卓谷歌地图中
【发布时间】:2014-05-18 14:17:39
【问题描述】:

我使用谷歌地图在两个位置之间获得了一条折线,当我想通过使用 Json 解析使用此 URL 来获取这两个位置之间的路线和方向时 https://maps.googleapis.com/maps/api/directions/json?origin=fromlocation&destination=destinationlocation&sensor=false&key=********API KEY********* 它正在将json解析为 { "error_message" : "此 IP、站点或移动应用程序无权使用此 API 密钥。", “路线”:[], “状态”:“REQUEST_DENIED” } 我已经使用 keytool 以及包名和指纹密钥获得了授权的 APIKEY

这是我所做的代码,提前感谢我的英语......

私有类 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();


}

}

【问题讨论】:

    标签: android json google-maps


    【解决方案1】:

    2019 年 6 月 28 日更新:

    以前,谷歌过去允许呼叫方向、地理位置 api 没有 api 密钥,最多为 certain extent。这是一个方便的开发功能,因为您可以在浏览器中更改 url。他们已经更新了他们的政策。

    现在您需要提供一个有效的 api 密钥。更多信息请关注link

    上一个答案:

    尝试删除 API 密钥。我使用了它,它返回给我一个有效的 json。

    【讨论】:

    • 但是为什么。为什么我们不能使用它?
    • @SherazAhmadKhilji 可能是因为它不是受支持的 url 格式。
    • 不,它给出了错误消息 - 您必须使用 API 密钥来验证对 Google Maps Platform API 的每个请求。
    • @debo.stackoverflow 更新了答案。以前,我可以在没有 api 密钥的情况下进行 api 调用。现在我不能了。
    猜你喜欢
    • 2014-03-22
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2014-06-10
    相关资源
    最近更新 更多