我正在尝试在 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();
}
}
}
}
}