2014-09-18 30 views
0

我正在使用Places API,當我嘗試檢查附近的地方時,我收到了INVALID_REQUEST。這是我的代碼片段 - 這有什麼問題嗎?我錯過了什麼嗎?Google Places API(Android)INVALID_REQUEST - 我錯過了什麼嗎?

 urlString.append("&location="); 
     urlString.append(Double.toString(latitude)); 
     urlString.append(","); 
     urlString.append(Double.toString(longitude)); 
     urlString.append("&rankby=distance"); 
     urlString.append("&types="+place); 
     urlString.append("&sensor=false&key=" + API_KEY); 

'place'是一個輸入到這個方法中的字符串。

回答

0

如果您想嘗試一個爲Google Places API提供Java接口的庫,您可以查看Sprockets(披露:我是開發人員)。它允許你像下面那樣查詢,所以你不必擔心URL,查詢字符串和JSON響應。

List<Place> places = Places.nearbySearch(Params.create() 
     .latitude(47.60567).longitude(-122.3315).radius(5000) 
     .keyword("swimming").openNow(true).maxResults(5)).getResult(); 

請參閱Places類以瞭解所有可能的請求及其詳細信息。

0

由於您沒有提及輸出,因此您可能會丟失網址中的

urlString.append("https://maps.googleapis.com/maps/api/place/nearbysearch/") 
urlString.append("json?") 
urlString.append("location="); 
urlString.append(Double.toString(latitude)); 
urlString.append(","); 
urlString.append(Double.toString(longitude)); 
urlString.append("&rankby=distance"); 
urlString.append("&types="+place); 
urlString.append("&sensor=false&key=" + API_KEY); 

&在位置過時之前。

0

在我的情況下,我的網址不正確,我放置了$標誌而不是&