繁体   English   中英

未正确获取 Google 地点结果

[英]Not getting the Google places result properly

我试图在 json 中获取 Google 位置的结果。但每次我得到的结果状态为请求被拒绝..

    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();
                }
            }
        }


    }
}

您没有传递reqUrl

URI website = new URI (baseUrl);

试试这个:

URI website = new URI (reqUrl);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM