// Functionality for taps of the "Get Directions" button public void getDirections(View view) { // 1. clear previous results textViewResult.setText(""); if (map != null && mapRoute != null) { map.removeMapObject(mapRoute); mapRoute = null; } // 2. Initialize RouteManager RouteManager routeManager = new RouteManager(); // 3. Select routing options via RoutingMode RoutePlan routePlan = new RoutePlan(); RouteOptions routeOptions = new RouteOptions(); routeOptions.setTransportMode(RouteOptions.TransportMode.PEDESTRIAN); routeOptions.setRouteType(RouteOptions.Type.FASTEST); routePlan.setRouteOptions(routeOptions); // 4. Select Waypoints for your routes // START: Nokia, Burnaby routePlan.addWaypoint(new GeoCoordinate(Src.Lat, Src.Longt)); ; // END: Airport, YVR routePlan.addWaypoint(new GeoCoordinate(Dest.Lat, Dest.Longt)); // 5. Retrieve Routing information via RouteManagerListener RouteManager.Error error = routeManager.calculateRoute(routePlan, routeManagerListener); if (error != RouteManager.Error.NONE) { Toast.makeText( getApplicationContext(), "Route calculation failed with: " + error.toString(), Toast.LENGTH_SHORT) .show(); } };
public void onCalculateRouteFinished( RouteManager.Error errorCode, List<RouteResult> result) { if (errorCode == RouteManager.Error.NONE && result.get(0).getRoute() != null) { // create a map route object and place it on the map mapRoute = new MapRoute(result.get(0).getRoute()); map.addMapObject(mapRoute); // Get the bounding box containing the route and zoom in GeoBoundingBox gbb = result.get(0).getRoute().getBoundingBox(); map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION); textViewResult.setText( String.format( "Route calculated with %d maneuvers.", result.get(0).getRoute().getManeuvers().size())); } else { textViewResult.setText( String.format("Route calculation failed: %s", errorCode.toString())); } }