没有让Google正确放置结果

时间:2012-04-11 09:17:56

标签: android json url google-places

我正在尝试将Google的结果放在json中。但每次我得到结果 状态为请求拒绝..

    package com.json.trial;


public class GetMethodEx {
    String API_KEY = "My Places Key";

    String baseUrl="https://maps.googleapis.com/maps/api/place/search/json?";
    key="AIzaSyCQ6m78y0CLClpvldSwY-aI2JbbZGoFx68";
    double latitude,longitude;

    public String getInternetData()throws Exception{

        latitude=-33.8670522;
        longitude=151.1957362;

        GenericUrl reqUrl = new GenericUrl(baseUrl);

         reqUrl.put("location", Double.toString(latitude) + "," + Double.toString(longitude));
        reqUrl.put("radius", 500);
        reqUrl.put("types", "");
        reqUrl.put("sensor", "false");
        reqUrl.put("key", API_KEY);

        BufferedReader in = null;
        String data = null;
        try{
            HttpClient client = new DefaultHttpClient();
            URI website = new URI (baseUrl);
            HttpGet request = new HttpGet();
            request.setURI(website);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String l="";
            String nl = System.getProperty("line.separator");

            while((l=in.readLine())!= null){
                sb.append(l + nl);
            }
            in.close();
            data = sb.toString();
            return data;
        }finally{
            if(in!=null){
                try{
                    in.close();
                    return data;
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }


    }
}

1 个答案:

答案 0 :(得分:1)

您没有在

中传递reqUrl
URI website = new URI (baseUrl);

试试这个:

URI website = new URI (reqUrl);