2012-04-11 96 views
0

我想獲得谷歌地方在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(); 
       } 
      } 
     } 


    } 
} 
+0

什麼是你生成的URL? – 2012-04-11 09:22:32

+0

我已經嘗試了學校和食物類型 – santosh407 2012-04-11 09:24:57

+0

我試過這個,它的工作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

回答

1

你不及格reqUrl

URI website = new URI (baseUrl); 

試試這個:

URI website = new URI (reqUrl); 
+0

看到上面的代碼..你可以告訴我,我提供的經緯度從CurrentLocation類到主類是好的或不.. ..tw再次感謝您的答覆...在此期間,我會試試這個和讓你知道.. – santosh407 2012-04-11 18:16:37

+0

感謝您的回覆..我已經完成了wat你告訴...但仍然沒有幫助。但我發現我的問題,並解決它,謝謝 – santosh407 2012-04-12 20:04:31

+0

可以請你分享,你的解決方案是什麼? – 2013-01-10 07:38:25

相關問題