开发者

Google Map Api always return request_denied with HttpClient

开发者 https://www.devze.com 2023-04-03 20:20 出处:网络
String webURL = \"https://maps.googleapis.com/maps/api/place/search/json\"; Map<String,String> params = new HashMap<String,String>();
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()开发者_JAVA技巧;
        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();

Why the above code always return me this error

"html_attributions" : [], "results" : [], "status" : "REQUEST_DENIED"]

I have also tried with this logic

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


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

Basically I am just trying to fetch some Results from GMapI. What seems to me that its not setting parameters with URL also give me an idea that how i can print the complete url which is executing at that time.


What I was mistaking there is just to encode the parameters in UTF-8 after which my problem has resolved :)

0

精彩评论

暂无评论...
验证码 换一张
取 消