Download official Demo
Download and Install official Demo:
Github.com/mapbox/mapb… After downloading. Import to AS, select build. KTP file in mapbox-maps-Android root directory, and set password
Configure mapbox_access_token in developer-config.
Register Token
Register MAPBOX_DOWNLOADS_TOKEN
Docs.mapbox.com/android/map… Official guide page
Account.mapbox.com/access-toke… Create a token to be used in the build.kt of Project and in the gradle configuration file of the new version of Project Setting. kt. Check the DOWNLOADS:READ option.
If Android Studio is below Arctic Fox (2020.3.1) and Gradle version is below V6.0, configure the build.gradle file
allprojects {
repositories {
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
}
Copy the code
For Android Studio Arctic Fox(2020.3.1) and gradle version higher than V6.0, configure setting.gradle file
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = MAPBOX_DOWNLOADS_TOKEN
}
}
}
}
Copy the code
Mapbox JAR package introduced in project Module
API "com. Mapbox. Maps: android: 10.3.0"Copy the code
Replace the MAPBOX_DOWNLOADS_TOKEN registered above.
Register with mapbox_access_token in V10.2 and above:
ResourceOptionsManager.getDefault(requireContext(), getString(R.string.mapbox_key)).update {
tileStoreUsageMode(TileStoreUsageMode.READ_ONLY)
}
Copy the code
Here are the differences between the Version 10 and Pre 10 packages
Package | pre-v10 | v10 |
---|---|---|
Maven group ID for map | com.mapbox.mapboxsdk |
com.mapbox.maps |
Maven artifact ID for map | mapbox-android-sdk |
android |
Maven group ID for plugins | com.mapbox.mapboxsdk |
com.mapbox.plugin |
Maven group ID for plugins | com.mapbox.mapboxsdk |
com.mapbox.extension |
Maven artifact ID for plugins | mapbox-android-plugin-PLUGINNAME |
maps-PLUGINNAME |
Package name for maps | com.mapbox.mapboxsdk.maps |
com.mapbox.maps |
MapView class in the layout |
com.mapbox.mapboxsdk.maps.MapView |
com.mapbox.maps.MapView |
Location-related operations no longer need to import Plugin packages separately.
Normally, MapView is almost ready to use.
MapView lifecycle methods are reduced to onStart(), onStop(), onLowMemory(), onDestory()
More usage differences can be found in the official documentation:
Docs.mapbox.com/android/map…
Normally, you can create a Fragment to load and display the MapView.
Here I encountered a problem in the project that hindered me for a long time, and finally found a solution in the issues in the Github demo code.
Github.com/mapbox/mapb…
Return the following error:
java.lang.UnsatisfiedLinkError: No implementation found for void com.mapbox.maps.assets.AssetManagerProvider.initialize(android.content.res.AssetManager) (tried Java_com_mapbox_maps_assets_AssetManagerProvider_initialize and Java_com_mapbox_maps_assets_AssetManagerProvider_initialize__Landroid_content_res_AssetManager_2)
at com.mapbox.maps.assets.AssetManagerProvider.initialize(Native Method)
at com.mapbox.maps.MapController.<init>(MapController.kt:65)
at com.mapbox.maps.MapView.<init>(MapView.kt:101)
at com.mapbox.maps.MapView.<init>(MapView.kt:52)
at com.mapbox.maps.MapView.<init>(MapView.kt:52)
Copy the code
Finally, the vowel was added to our App’s manifest.xml file
<! -- work manager --> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="remove" /> <! -- work manager -->Copy the code
The solution given in Issues is to add the following code to the custom Application onCreate() method:
AppInitializer.getInstance(this)
.initializeComponent(MapboxMapsInitializer::class.java)
Copy the code
Support for the upgrade to V10 is preliminarily complete.
\