Show navigation view of mapbox with direction units km/minutes instead of miles/feets

寵の児 提交于 2019-12-11 10:57:56

问题


how to Show navigationview of mapbox with direction units km/minutes instead of miles/feets

 String awsPoolId = null;
        boolean simulateRoute = false;

        Log.e("=origin==", "" + origin);
        Log.e("=desti==", "" + destination);

        // Call this method with Context from within an Activity
        NavigationLauncher.startNavigation(GotoPickup.this, origin, destination, awsPoolId, simulateRoute);

回答1:


You have to set your desired type (METRIC). I calculate the route from Mapbox (pay attention to voice instructions) and pass it to the NavigationLauncher:

NavigationRoute.builder()
.voiceUnits(DirectionsCriteria.METRIC)
...
.build()
.getRoute(new Callback<DirectionsResponse>() {
        // Checkout mapbox tutorials for this part
        DirectionsRoute directionsRoute = ...

        NavigationLauncherOptions options = NavigationLauncherOptions.builder()
            .directionsRoute(directionsRoute)
            .unitType(NavigationUnitType.TYPE_METRIC)
            .build();

        NavigationLauncher.startNavigation(MyActivity.this, options);
    }
});

Works fine with com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.13.0




回答2:


       // See this is only for Navigation of mapbox if you are using mapbox that you //can use this code directly for navigation

     //   First, we have to define Latlng of mapbox

         com.mapbox.mapboxsdk.geometry.LatLng originCoord;

       //than put your your lat,lng in this like that

        originCoord = new com.mapbox.mapboxsdk.geometry.LatLng(23.040105, 72.561381);
   //     Now, for navigation we mapbox want "Point" type of datatype so we have //to change Latlng to point type  like that...
          Point origin;
         Point originPosition;
          originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());

      //  than i will put this point type data to other point type because. i need //it. you can directly put this point on navigation class

        origin = originPosition;
      //like that....


         final NavigationViewOptions options = NavigationViewOptions.builder()
                                    .origin(origin)
                                    .destination(destination)
                                    .awsPoolId(awsPoolId)
                                    .shouldSimulateRoute(simulateRoute)
                                    .build();
                            // Call this method with Context from within an Activity
                            NavigationLauncher.startNavigation(MainActivity.this, options);

    //    in this code i will show you only for source LatLng you have to do same //for destination code 
    ///    hope you will understand that ......
     //If you not using mapbox refer this link.....https://www.mapbox.com/



回答3:


 all objects are:- Global define 
    com.mapbox.mapboxsdk.geometry.LatLng originCoord;
    Point originPosition;
      Point origin;

  originCoord = new com.mapbox.mapboxsdk.geometry.LatLng(23.040105, 72.561381);
     originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());
     origin = originPosition;
    Pass "origin" on " .origin(origin)" directly 
    Destination is same as this 



     final NavigationViewOptions options = NavigationViewOptions.builder()
                            .origin(origin)
                            .destination(destination)
                            .awsPoolId(awsPoolId)
                            .shouldSimulateRoute(simulateRoute)
                            .build();
                    // Call this method with Context from within an Activity
                    NavigationLauncher.startNavigation(MainActivity.this, options);


来源:https://stackoverflow.com/questions/47199033/show-navigation-view-of-mapbox-with-direction-units-km-minutes-instead-of-miles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!