0
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。

4

1 回答 1

0

我错在那里只是将参数编码为UTF-8,之后我的问题就解决了:)

于 2011-09-11T20:40:42.017 回答