androidgoogle-directions-api

DirectionsApiRequest not working below from SDK 26 Android phone


I am using DirectionsApiRequest to get direction information from google it work fine from SDK 26 to above android phone.But it did not give any result or error on android phone below to SDK 26.

DirectionsApiRequest directionsApiRequest = new DirectionsApiRequest(mGeoApiContext);
  
    directionsApiRequest.origin(new com.google.maps.model.LatLng(latLngList.get(0).latitude, latLngList.get(0).longitude));
    directionsApiRequest.destination(new com.google.maps.model.LatLng(latLngList.get(1).latitude, latLngList.get(1).longitude));
    directionsApiRequest.mode(TravelMode.DRIVING);
 
    directionsApiRequest.alternatives(false);
    

  
    directionsApiRequest.setCallback(new PendingResult.Callback<DirectionsResult>() {
        @Override
        public void onResult(DirectionsResult result) {
          
            currentTripDuration = String.valueOf(result.routes[0].legs[0].duration);
            currentTripTime = String.valueOf(result.routes[0].legs[0].distance);
           
        }

        @Override
        public void onFailure(Throwable e) {
            Log.e("calculateDirections", "calculateDirections: Failed to get directions: " + e.getMessage());
        }
    });
implementation 'com.google.android.gms:play-services-maps:17.0.0'
/*google location*/
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.libraries.places:places:2.4.0'


/*google direction*/
implementation 'com.google.maps:google-maps-services:0.15.0'

Solution

  • This API is not recommended for Android Usage as per this issue https://github.com/googlemaps/google-maps-services-java/issues/552 please hit direction API by using the retrofit builder