【发布时间】:2018-09-24 13:58:25
【问题描述】:
我正在使用 URLConnection 连接到 URL 以获取 android 中两个位置之间的距离和时间。每次它返回“REQUEST_DENIED”。我生成了没有任何限制的密钥,并启用了 Google Maps Android API、Google Maps Geocoding API 和 Google Places API Web Service。代码sn-p:
返回的响应是: { “目的地地址”:[], "error_message" : "此 API 项目无权使用此 API。", “origin_addresses”:[], “行”:[], “状态”:“REQUEST_DENIED” }
URL mapUrl = new URL("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=My_Key");
URLConnection connection = mapUrl.openConnection();
InputStream in = connection.getInputStream();
InputStreamReader isw = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(isw);
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
另请注意,当我在浏览器中粘贴相同的 URL 时,有时结果会显示在浏览器中。但不总是。如果它显示“REQUEST_Denter image description hereENIED”,此后它总是显示相同。我尝试再次禁用和启用 API 服务。第一次启用后,我在浏览器中得到了结果,但不是通过 android 应用程序。 我该如何解决这个问题?请求数也不是问题,因为它在限制范围内。
【问题讨论】:
标签: android google-maps android-studio google-places-api