Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法连接到google directions API_Android_Google Maps_Google Api_Google Directions Api - Fatal编程技术网

Android 无法连接到google directions API

Android 无法连接到google directions API,android,google-maps,google-api,google-directions-api,Android,Google Maps,Google Api,Google Directions Api,我正在尝试使用Android应用程序使用Google Directions API 在谷歌开发者控制台上,我创建了一个项目并选择了Android平台 使用我唯一的包名和SHA1密钥,我得到了一个API密钥 在我的android代码中,我使用此API密钥发送HTTP请求 url = "https://maps.googleapis.com/maps/api/directions/json?origin=Dhanmondi&destination="+destination+"&ke

我正在尝试使用Android应用程序使用Google Directions API

在谷歌开发者控制台上,我创建了一个项目并选择了Android平台

使用我唯一的包名和SHA1密钥,我得到了一个API密钥

在我的android代码中,我使用此API密钥发送HTTP请求

url = "https://maps.googleapis.com/maps/api/directions/json?origin=Dhanmondi&destination="+destination+"&key=" + apiKey;



public String sendGetRequest(String uri) {
    try {
        URL url = new URL(uri);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

        String result;

        StringBuilder sb = new StringBuilder();

        while((result = bufferedReader.readLine())!=null){
            sb.append(result);
        }

        return sb.toString();
    } catch (Exception e) {
        return null;
    }
}
然而,我得到了这个错误

此IP、站点或移动应用程序无权使用此API密钥。从IP地址112.13.34.221接收到请求,且推荐人为空。

我已经为Android API以及谷歌方向、谷歌道路和谷歌地点API启用了谷歌地图


确保在创建api密钥时正确指定了包名

您是否创建了android密钥、服务器密钥或浏览器密钥。?确保您已经创建了android密钥。 方向api需要android密钥

确保您已在google控制台中为api密钥启用了方向api

在创建api时请记住所有这些要点,并让我们知道接下来会发生什么


谢谢

当您没有在Google控制台上启用Api时,通常会出现此类错误。所以,请在控制台上启用Api。()


如果您的请求格式不正确或提供的签名无效,Google Maps Directions API将返回HTTP 403(禁止)错误。()

您是否在密钥创建过程中添加了相同的包名,是否启用了方向api,是否在清单中添加了密钥我有您提到的所有内容@war\hero返回的错误状态码是什么,如果您在浏览器选项卡中粘贴url,请检查是否得到响应状态码是403。。。我已经编辑了我的问题,提供了截图。。。这个URL在浏览器中不起作用,因为我在创建我的项目时选择了android平台@war_hegorit与URL有关Parsing我遵循了您描述的所有步骤,但仍然出现了相同的错误@Sagar Nayak