【问题标题】:How to get location names nearby my current location using api v2 in android如何在android中使用api v2获取我当前位置附近的位置名称
【发布时间】:2013-08-28 15:19:13
【问题描述】:

我正在开发一个应用程序,我必须在其中获取当前位置(纬度/经度)附近的所有位置名称,并且所有位置都应在 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();
    }

【问题讨论】:

    标签: android


    【解决方案1】:

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

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

    【讨论】:

    • 使用浏览器键代替安卓应用键
    • 非常感谢,现在我正在使用浏览键,它工作正常
    【解决方案2】:
    {
           "debug_info" : [],
           "html_attributions" : [],
           "results" : [],
           "status" : "REQUEST_DENIED"
        }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多