直接进入地址栏时,您必须使用 API 密钥来验证对 Google Maps Platform APIs 错误的每个请求

Iba*_*408 6 api

我收到这样的错误:

    {
   "error_message" : "This API project is not authorized to use this API.",
   "results" : [],
   "status" : "REQUEST_DENIED"
}
Run Code Online (Sandbox Code Playgroud)

每当我运行这个: https://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&key=AIzaSyCKyVbBzwtgkyuut7P5mxK9vcOWMygCfp0

在我关注的示例视频中,他得到如下结果: 在此处输入图片说明

Moo*_*man 6

就我而言,我在地址链接中有#,input=City Clinical # 89所以我不得不将其删除

  • 只是为了澄清。我正在使用 API 密钥,但由于地址中存在“#”,我仍然收到错误。正如这个答案所示,删除“#”后,我没有任何问题。 (2认同)

小智 5

您需要一个 API 密钥。否则它不会工作。

要获取 API 密钥,您必须访问此网页https://cloud.google.com/maps-platform/#get-started并选择您需要的产品。还要选择或创建一个项目,最后您必须设置一个计费帐户。不幸的是,据我所知,它不是免费的。


小智 5

发布值如下:

  String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
    // Destination of route
    String str_dest = "destination=" + dest.latitude + "," + dest.longitude;

    // Sensor enabled
    String sensor = "sensor=true";
    String mode = "mode=driving";
    String key = "key="+getResources().getString(R.string.google_maps_key);
    // Building the parameters to the web service
    String parameters = str_origin + "&" + str_dest + "&" + sensor + "&" + mode + "&" + key;

    // Output format
    String output = "json";

    // Building the url to the web service
    String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters;
Run Code Online (Sandbox Code Playgroud)