我想獲得谷歌地方在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();
}
}
}
}
}
什麼是你生成的URL? – 2012-04-11 09:22:32
我已經嘗試了學校和食物類型 – santosh407 2012-04-11 09:24:57
我試過這個,它的工作https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&type=%22school %22&sensor = false&key = AIzaSyCQ6m78y0CLClpvldSwY-aI2JbbZGoFx68 – 2012-04-11 09:26:01