


ResultDistanceMatrix.java class holds the response from Distance Matrix API. Public class LocationA implements Serializable String String lng Public class Geometry implements LocationA locationA Public class CustomA implements Serializable Geometry String String name Public class Root implements Serializable List customA = new String status PlacesPOJO.java is the file which holds the response from Places API. Public interface ApiInterface = "type", encoded = true) String type, = "location", encoded = true) String location, = "name", encoded = true) String name, = "opennow", encoded = true) boolean opennow, = "rankby", encoded = true) String rankby, = "key", encoded = true) String // origins/destinations: LatLng as stringĬall String key, String origins, String destinations)
Google earth json query code#
The ApiInterface.java code is given below package addConverterFactory(GsonConverterFactory.create()) OkHttpClient client = new OkHttpClient.Builder().readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).addInterceptor(interceptor).build() HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() Public static final String GOOGLE_PLACE_API_KEY = "ADD_YOUR_API_KEY_HERE" The APIClient.java code is given below: package Google Places API Example CodeĪdd the following dependencies inside the adle file compile ':play-services-location:10.2.1'Ĭompile ':play-services-places:10.2.1'Ĭompile '2:retrofit:2.1.0'Ĭompile '2:converter-gson:2.1.0'Ĭompile '3:logging-interceptor:3.4.1'Ĭompile '3:okhttps:3.4.1'Ĭompile 'io.nlopez.smartlocation:library:3.3.1'Ĭompile ':cardview-v7:25.3.0'Ĭompile ':recyclerview-v7:25.3.0'Ĭompile 'io.nlopez.smartlocation:library:3.3.1' is a LocationTracking third party library that reduces the boilerplate code. APIClient and ApiInterface for using Retrofit and the endpoints. Two POJO classes for converting the JSON responses to Gson from the Google places API and Distance Matrix API. A Model class that holds the data for each RecyclerView row. The Project consists of a single Activity. Example: restaurant dominos or cafe vegetarian Google Places API Example Project Structure We’ll be searching places based on the type and name keywords that’ll be entered in the EditText and separated by a space. We’ll be developing an application that allows us to search nearby places based on our current location and display the places in a RecyclerView. Let’s jump onto the business end of this tutorial. avoid : Introduces restrictions to the route such as tolls, indoor etcįor more details visit this page.mode : this expects a value among driving, bicycling, walking, transit.We can also pass the addresses/place id instead of coordinates and the service automatically converts them into the latitude-longitude coordinates to calculate distance and duration. We can pass more than one set of coordinates separated by pipelines(|). origins - This contains the starting point for calculating travel distance and time. The required parameters are origins, destinations and the key. A Distance Matrix API url is of the form: The Distance Matrix API is used to calculate the distance and time between two or more points. The optional parameters can be opennow, pagetoken etc. type : values can be restaurant, cafe etc.name: values can be mcdonalds, kfc etc.Note: rankby=distance requires specifying either of the following parameters: rankby=distance or radius : If one is used the other can’t be used.Json is the recommended output, the other being xml The Required parameters are: A Nearby Search request is an HTTP URL of the following form: Google Places API Web Service allows us to query places based upon a few parameters such as the type of place, whether a place is open right now etc. We’ll be using the Google Places API Web Service with Distance Matrix API in the application. In this tutorial, we’ll be developing an application that displays the nearby places of our choice along with the approximate distance and time from our current location. Google Places API can be used to find nearby places.
