0

can anyone please tell me how to use google places api in android. I am developing this application in eclipse where i need to find the nearest petrol stations and garages near my area. I went through numerous websites. i didnt find a proper answer. I need a sample code since i am new to json concepts.

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
S.K
  • 609
  • 1
  • 8
  • 14

1 Answers1

0

You can use Google API Java Client for Google Places API in Android . See my answer for a short snippet https://stackoverflow.com/a/12824796/1147466

Community
  • 1
  • 1
shreks7
  • 422
  • 4
  • 10