Start Android Navigation for Result

I am creating an application where I need to start a navigation application and then use the result (most importantly the guided distance). I am starting a navigation activity with startActivityForResult and using the "google.navigation" schema. Like this:

Intent i = new Intent(
    Intent.ACTION_VIEW,
    Uri.parse("google.navigation:q=Somewhere"));
startActivityForResult(i,1);

      

This works great, I get a callback when the activity is executed but some of the activity data is empty.

Is there a way to do this?

Is there a navigation history where I can view the last trip for data?

Best wishes Jacob Simon-Gard

+3


source to share


3 answers


I am not aware of calls from Google Navigation. But if you are only interested in getting the distance, you can continue listening to location updates in the background and calculate the distance yourself. The following function uses LatLang to calculate the distance between two coordinates: android.location.Location

public double getGeodesicDistance(LatLng from, LatLng to){
    Location _fromLoc = new Location("From location");
    _fromLoc.setLatitude(from.latitude);
    _fromLoc.setLongitude(from.longitude);

    Location _toLoc = new Location("To location");
    _toLoc.setLatitude(to.latitude);
    _toLoc.setLongitude(to.longitude);

    return Math.round(_fromLoc.distanceTo(_toLoc)); // distance in metres
}

      



But if you choose to take this approach, you must detect sudden spikes in GPS data and handle them accordingly.

+2


source


Is there a way to do this?

No, you cannot get the action to give you a result. It is up to the authors of the activity, not the caller, to determine whether an action supports an outcome.



Is there a navigation history where I can view the last trip for data?

There is no documented API (which includes a schema google.navigation

) in the Google Navigation Android app .

+3


source


You can get the location right before starting navigation and get it again after closing navigation and calculate the difference.

+2


source







All Articles