如何在android中使用api v2在我的当前位置附近获取位置名

如何在android中使用api v2在我的当前位置附近获取位置名,android,Android,我正在开发一个应用程序,在这个应用程序中,我必须获取当前位置附近的所有位置名称(lat/long),并且所有位置的半径都应在1000米以内 现在我点击下面的API URL来实现: 每次我都会得到回应: { "debug_info" : [], "html_attributions" : [], "results" : [], "status" : "REQUEST_DENIED" } 我的代码: private String

我正在开发一个应用程序,在这个应用程序中,我必须获取当前位置附近的所有位置名称(lat/long),并且所有位置的半径都应在1000米以内

现在我点击下面的API URL来实现:

每次我都会得到回应:

 {
       "debug_info" : [],
       "html_attributions" : [],
       "results" : [],
       "status" : "REQUEST_DENIED"
    }
我的代码:

private String makeUrl(double latitude, double longitude,String place) 
{
     StringBuilder urlString = new StringBuilder("https://maps.googleapis.com/maps/api/place    /search/json?");

        if (place.equals("")) {
            urlString.append("&location=");
            urlString.append(Double.toString(latitude));
            urlString.append(",");
            urlString.append(Double.toString(longitude));
            urlString.append("&radius=1000");
            //urlString.append("&types="+place);
            urlString.append("&sensor=false&key=" + API_KEY);
        } else {
            urlString.append("&location=");
            urlString.append(Double.toString(latitude));
            urlString.append(",");
            urlString.append(Double.toString(longitude));
            urlString.append("&radius=1000");
            //urlString.append("&types="+place);
            urlString.append("&sensor=false&key=" + API_KEY);
        }

        return urlString.toString();
    }

private String getUrlContents(String theUrl) 
    {
        StringBuilder content = new StringBuilder();

        try {
            URL url = new URL(theUrl);
            URLConnection urlConnection = url.openConnection();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()), 8);
            String line;
            while ((line = bufferedReader.readLine()) != null) 
            {
                content.append(line + "\n");
            }

            bufferedReader.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        return content.toString();
    }

请求被拒绝
表示您使用了错误的密钥。启用
放置API
,然后重试

启用
Places API

{
       "debug_info" : [],
       "html_attributions" : [],
       "results" : [],
       "status" : "REQUEST_DENIED"
    }
据说你用错了钥匙 请看
关于如何获取新的API密钥,请使用浏览器密钥而不是android应用程序密钥。非常感谢,现在我使用的是浏览密钥,它工作正常