0

谁能告诉我如何在android中使用google places api。我正在eclipse中开发这个应用程序,我需要找到我所在地区附近最近的加油站和车库。我浏览了许多网站。我没有找到正确的答案。我需要一个示例代码,因为我是 json 概念的新手。

public class place  {

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;
  }
}//StoresNearMe
4

1 回答 1

0

您可以在 Android 中为 Google Places API 使用 Google API Java 客户端。请参阅我的简短回答https://stackoverflow.com/a/12824796/1147466

于 2012-10-10T17:36:58.893 回答