Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java google在android中放置api的示例代码_Java_Android_Json_Google Places Api - Fatal编程技术网

Java google在android中放置api的示例代码

Java google在android中放置api的示例代码,java,android,json,google-places-api,Java,Android,Json,Google Places Api,有谁能告诉我如何在android中使用GooglePlacesAPI吗。我正在eclipse中开发这个应用程序,我需要找到离我所在地区最近的加油站和车库。我浏览了很多网站。我没有找到正确的答案。我需要一个示例代码,因为我不熟悉json概念 public class place { private static final String PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/search/json?";

有谁能告诉我如何在android中使用GooglePlacesAPI吗。我正在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

您可以使用Android中的GooglePlacesAPI的GoogleAPI Java客户端。请参阅我的答案以获取简短的片段