メインコンテンツまでスキップ

Turn-By-Turn using NavigationView

Note

This example is a part of the Navigation SDK Examples. You can find the values for all referenced resources in the res directory. For example, see res/values/strings.xml for R.string.* references used in this example. The dependencies can be found here.The examples use View binding.See setup documention if necessary.

mapbox_activity_navigation_view
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.navigation.dropin.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:accessToken="@string/mapbox_access_token"
xmlns:app="http://schemas.android.com/apk/res-auto">

</com.mapbox.navigation.dropin.NavigationView>
NavigationViewActivity.kt
package com.mapbox.navigation.examples.dropinui.basic

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.navigation.dropin.NavigationView
import com.mapbox.navigation.examples.databinding.MapboxActivityNavigationViewBinding

/**
* The example demonstrates how to inflate [NavigationView] using XML to render a complete
* turn-by-turn experience.
*
* Before running the example make sure you have put your access_token in the correct place
* inside [app-preview/src/main/res/values/mapbox_access_token.xml]. If not present then add
* this file at the location mentioned above and add the following content to it
*
* <?xml version="1.0" encoding="utf-8"?>
* <resources xmlns:tools="http://schemas.android.com/tools">
* <string name="mapbox_access_token"><PUT_YOUR_ACCESS_TOKEN_HERE></string>
* </resources>
*
* The example uses replay location engine to facilitate navigation without physically moving.
*/
class NavigationViewActivity : AppCompatActivity() {

private lateinit var binding: MapboxActivityNavigationViewBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = MapboxActivityNavigationViewBinding.inflate(layoutInflater)
setContentView(binding.root)

// This allows to simulate your location
binding.navigationView.api.routeReplayEnabled(true)
}
}
この{Type}は役に立ちましたか?