navigation_with_mapbox 0.0.2
navigation_with_mapbox: ^0.0.2 copied to clipboard
Add Turn By Turn Navigation to Your Flutter Application Using MapBox.
navigation_with_mapbox #
Add Turn By Turn Navigation to Your Flutter Application Using MapBox.
Android Configuration #
- Mapbox APIs and vector tiles require a Mapbox account and API access token. Add your token in strings.xml file of your android apps res/values/ path. The string key should be "mapbox_access_token". You can obtain an access token from the Mapbox account page.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="mapbox_access_token" translatable="false">ADD_MAPBOX_ACCESS_TOKEN_HERE</string>
</resources>
- Add the following permissions to the app level Android Manifest
<manifest>
...
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
</manifest>
- Add the MapBox Downloads token with the
downloads:read
scope to your gradle.properties file in Android folder to enable downloading the MapBox binaries from the repository. To secure this token from getting checked into source control, you can add it to the gradle.properties of your GRADLE_HOME which is usually at $USER_HOME/.gradle for Mac. This token can be retrieved from your MapBox Dashboard. You can review the Token Guide to learn more about download tokens
MAPBOX_DOWNLOADS_TOKEN=sk.XXXXXXXXXXXXXXX
After adding the above, your gradle.properties file may look something like this:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
MAPBOX_DOWNLOADS_TOKEN=sk.XXXXXXXXXXXXXXX
Usage #
Declare an instance
//instantiate our plugin class
final _navigationWithMapboxPlugin = NavigationWithMapbox();
() async {
//in an asynchronous function we call the method that starts the map
await _navigationWithMapboxPlugin.startNavigation(
//origin refers to the user's starting point at the time of starting the navigation
origin:
WayPoint(latitude: 4.809432, longitude: -75.700660),
//destination refers to the end point or goal for the user at the time of starting the navigation
destination:
WayPoint(latitude: 4.759335, longitude: -75.923914),
//if we enable this option we can choose a destination with a sustained tap
setDestinationWithLongTap: false,
//if we enable this option we will activate the simulation of the route
simulateRoute: false,
//optional, message that will be displayed when starting the navigation map
msg: '¡Buen viaje, disfruta de tu recorrido!',
//unit of measure in which the navigation assistant will speak to us
//optional, default: metric
voiceUnits: 'imperial',
//language in which the navigation assistant will speak to us
//optional, default: en
language: 'es',
//if we enable this option we can see alternative routes when starting the navigation map
//optional, default: false
alternativeRoute: true,
//the style or theme with which the navigation map will be loaded
//optional, default: streets, others: dark, light, traffic_day, traffic_night, satellite, satellite_streets, outdoors
style: 'traffic_night',
//refers to the navigation mode, the route and time will be calculated depending on this
//optional, default: driving, others: walking, cycling
profile: '');
}