我正在製作一個android應用程序,需要在我10km以內的本地區域進行搜索,並使用引腳將結果顯示在地圖上,例如:「Starbucks」,「Wallmart」,Shopping mall等。我在我的活動類中指定的搜索詞。並且要清楚:我不想在Google地圖中打開搜索,我希望它能在我自己的應用程序中顯示結果。但是我在執行搜索的代碼中出現錯誤。錯誤出現在以下東西:Google Places API - android
網址:網址不能得到解決或不是一個場 執行:該方法執行()是未定義的類型的HttpRequest 響應:響應不能得到解決或不是一個場
我使用三個包: com.mycompany.applicationname =默認包,其中包含主代碼,包括搜索碼 com.mycompany.applicationname.Model =含PlaceAutoComplete,PlacesList,地點等 com.mycompany .applicationname.PlacesRequests =包含PlaceRequest.java
請幫助我,我真的需要幫助,感謝這麼多提前
這是我使用來執行搜索代碼:
private static final String PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/json?";
private static final boolean PRINT_AS_STRING = false;
public void performSearch() throws Exception {
try {
System.out.println("Perform Search ....");
System.out.println("-------------------");
HttpRequestFactory httpRequestFactory = createRequestFactory(transport);
HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
request.url.put("key", API_KEY);
request.url.put("location", lat + "," + lng);
request.url.put("radius", 500);
request.url.put("sensor", "false");
if (PRINT_AS_STRING) {
System.out.println(request.execute().parseAsString());
} else {
PlacesList places = request.execute().parseAs(PlacesList.class);
System.out.println("STATUS = " + places.status);
for (Place place : places.results) {
System.out.println(place);
}
}
} catch (HttpResponseException e) {
System.err.println(e.response.parseAsString());
throw e;
}
}