2012-07-18 74 views
0

我正在處理需要檢索當前位置的附近餐館的應用程序。論壇建議我使用Google Places API。 當我閱讀Google Place API時,它說項目需要成爲「Google App Engine項目」+ Android客戶端。但我感到困惑,這將是一個正確的方式,因爲我對Google世界相當陌生。檢索當前位置的附近地點

有人可以建議我這將是檢索當前位置的附近餐館的最佳方式嗎?

謝謝。

回答

0

點擊此鏈接。 爲您的應用程序創建應用程序密鑰&您只需提出Http請求,&您將獲得Xml // json中的所有信息。 https://developers.google.com/places/documentation/

https://maps.googleapis.com/maps/api/place/search/xml?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

在上述網址,添加您的API密鑰& locaton。它會返回一個xml給你,包含所有500米的圓圈裏的所有restras。

此網址只接受取得請求。 Yov必須在Url本身中追加所有參數。

@Override 
       public void run() 
       { 
        String params="location="+(location.getLatitude())+","+(location.getLongitude())+"&radius=5000&types=food&sensor=false&key=your kay"; 
         try 
         { 
          http.getPlaces(new URL("https://maps.googleapis.com/maps/api/place/search/xml?"+params)); 
          Log.i("url", "https://maps.googleapis.com/maps/api/place/search/xml?"+params); 
          setList(); 
         } 
         catch (MalformedURLException e) 
         { 
          e.printStackTrace(); 
         } 
         catch (Exception e) 
         { 
          e.printStackTrace(); 
         } 

       } 
      }); 


public void getPlacesDetails(URL url) throws Exception { 
    try 
    { 
     connection = (HttpURLConnection) url.openConnection(); 
     connection.setDoInput(true); 
     connection.setDoOutput(true); 
     connection.setUseCaches(false); 

     connection.setConnectTimeout(TIMEOUT_CONNECT_MILLIS); 
     connection.setReadTimeout(TIMEOUT_READ_MILLIS); 
     connection.setRequestMethod("GET"); 

     inStream = (InputStream) connection.getInputStream(); 


     SAXParserFactory spf = SAXParserFactory.newInstance(); 
     SAXParser sp = spf.newSAXParser(); 
     XMLReader xr = sp.getXMLReader(); 

     HospitalDetailParser myXMLHandler = new HospitalDetailParser(); 
     xr.setContentHandler(myXMLHandler); 
     xr.parse(new InputSource(inStream)); 


    } 

    catch (MalformedURLException e) 
    { 

     Log.i("exception in sms", "" + e.toString()); 
     throw e; 
    } 

    catch (Exception e) 
    { 

     Log.i("exception in sms", "" + e.toString()); 
     throw e; 
    } 

} 
+0

也有一個「入門」指南到API的地方在:https://developers.google.com/academy/apis/maps/places/ – saxman 2012-07-18 22:45:53

+0

在使用谷歌API的地方,我得到一個「 VerifyError「在運行時。 LogCat說 - 「無法找到GenericUrl類」,但編譯顯示沒有這樣的錯誤。我在論壇上搜索並實施所有建議的解決方案,但仍然得到相同的錯誤...我錯過了什麼? – 2012-07-19 06:43:45

+0

你能提供相關的代碼和日誌嗎? 我已編輯答案。請檢查。 – Kamal 2012-07-19 09:34:54

相關問題