0

我正在开发一个应用程序,我必须在其中获取当前位置(纬度/经度)附近的所有位置名称,并且所有位置都应在 1000 米半径范围内。

现在我为此点击 API URL:

https://maps.googleapis.com/maps/api/place/search/json?&location=22.724376,75.879668&radius=1000&sensor=false&key=AIzaSyD6Lqfrfx5AEINisuSToz-poqXnwsWSYTY

我每次都得到回应:

 {
       "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();
    }
4

2 回答 2

1

REQUEST_DENIED表示您使用了错误的密钥。启用Places API然后尝试。

您也可以Browser Key在启用后使用Places API

于 2013-08-28T07:06:09.767 回答
1
{
       "debug_info" : [],
       "html_attributions" : [],
       "results" : [],
       "status" : "REQUEST_DENIED"
    }

据说您使用了错误的密钥请参阅https://developers.google.com/maps/documentation/javascript/tutorial?csw=1#api_key 了解如何获取新的 API 密钥,

于 2013-08-28T07:19:13.497 回答