Google Map Api始终使用HttpClient返回request_denied

时间:2011-09-10 22:52:37

标签: java google-maps-api-3 apache-httpclient-4.x

String webURL = "https://maps.googleapis.com/maps/api/place/search/json";
        Map<String,String> params = new HashMap<String,String>();
        params.put("location", "24.8844879,67.175255");
        params.put("radius", "500");
        params.put("sensor", "true");
        params.put("key", MY_KEY);

StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(
                webURL);
        if(params!=null){


            for(String param:params.keySet()){
                client.getParams().setParameter(param, params.get(param).toString());
            }

        }

        try {
            HttpResponse response = client.execute(httpGet);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();

为什么上面的代码总是给我这个错误

  

“html_attributions”:[],“results”:[],“status”:   “REQUEST_DENIED”]

我也试过这个逻辑

if(params!=null){
        HttpParams httpParams = new BasicHttpParams();


        for(String param:params.keySet()){
            httpParams.setParameter(param, params.get(param).toString());
        }
        httpGet.setParams(httpParams);
    }

基本上我只是想从GMapI中获取一些结果。在我看来,它没有设置URL参数也让我知道如何打印当时正在执行的完整URL。

1 个答案:

答案 0 :(得分:0)

我误以为只是用UTF-8对参数进行编码,之后我的问题解决了:)