【问题标题】:Google Map Api always return request_denied with HttpClientGoogle Map Api 总是使用 HttpClient 返回 request_denied
【发布时间】:2011-09-10 22:52:36
【问题描述】:
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”:[],“结果”:[],“状态”: "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。

【问题讨论】:

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


    【解决方案1】:

    我错了只是用 UTF-8 编码参数,之后我的问题就解决了 :)

    【讨论】:

      猜你喜欢
      • 2016-03-23
      • 1970-01-01
      • 2013-07-04
      • 2013-06-17
      • 2013-12-01
      • 1970-01-01
      • 2013-06-26
      • 2012-02-22
      • 1970-01-01
      相关资源
      最近更新 更多