Migrate to v11
This document is a guide for migrating from v10 of the Mapbox Maps SDK for Android to the v11. It includes information about new features, deprecated APIs, and breaking changes.
Version Compatibility
Version | Minimum Android Version | Kotlin Version | Target/Compile SDK Version | NDK Version | OpenGL |
---|---|---|---|---|---|
11.0.0 | 5.0 (API level 21) | 1.6.0 or later | 33 | 23.2.8568313 | OpenGL ES 3.0 |
Mapbox Maps SDK v11 was complied with the following dependencies:
- Kotlin 1.7.20 and binary compatibility with Kotlin compiler 1.6 and above.
- Compile SDK Version 33, which is also the minimum target SDK level for new apps published to Google Play Store.
- Android X libraries which requires
minCompileSdk (33)
, if you are not able to update to compileSDK 33, force an older version of Android X libraries in app’s build.gradle:
implementation("androidx.appcompat:appcompat") { version { strictly("1.4.2") } }
implementation("androidx.core:core-ktx") { version { strictly("1.8.0") } }
Explore new features
The Mapbox Standard Style and Mapbox Standard Satellite Styles
With the Mapbox Maps SDK v11 we are introducing Mapbox Standardand Mapbox Standard Satellite, our latest Mapbox style. The new Mapbox Standard core style enables a highly performant and elegant 3D mapping experience with powerful dynamic lighting capabilities, landmark 3D buildings, and an expertly crafted symbolic aesthetic. With Mapbox Standard and Mapbox Standard Satellite, we are also introducing a new paradigm for how to interact with map styles.
To set Mapbox Standard as the style for your map in v11 you can use the Style.STANDARD
constant like below:
mapboxMap.loadStyle(Style.STANDARD)
The Mapbox Standard and Mapbox Standard Satellite styles features 4 light presets: day
, dusk
, dawn
, and night
. The style light preset can be changed from the default, “Day”, to another preset with a single line of code. Here you identify which imported style (basemap
) you want to change the lightPresent
configuration on, as well as the value (dusk
) you want to change it to.
mapboxMap.loadStyle(Style.STANDARD) { style ->
style.setStyleImportConfigProperty(styleImportId, "lightPreset", Value.valueOf("dusk"))
}
Light preset "day " (default) | Light preset "dusk " |
---|---|
Changing the light preset will alter the colors and shadows on your map to reflect the time of day. For more information, see the Lighting API section. Similarly, you can set other configuration properties on the Standard style such as showing POIs, place labels, or specific fonts:
mapboxMap.loadStyle(Style.STANDARD) { style ->
style.setStyleImportConfigProperty(styleImportId, "showPointOfInterestLabels", Value.valueOf(false))
}
The Standard style offers 8 configuration properties for developers to change when they import it into their own style:
Property | Type | Description |
---|---|---|
showPlaceLabels | Bool | Shows and hides place label layers. |
showRoadLabels | Bool | Shows and hides all road labels, including road shields. |
showPointOfInterestLabels | Bool | Shows or hides all POI icons and text. |
showTransitLabels | Bool | Shows or hides all transit icons and text. |
show3dObjects | Bool | Shows or hides all 3d layers (3D buildings, landmarks, trees, etc.) including shadows, ambient occlusion, and flood lights. Important: configuration available starting from v11.5.1 SDK |
theme | String | Switches between 3 themes: default , faded and monochrome . Important: configuration available starting from v11.5.1 SDK |
lightPreset | String | Switches between 4 time-of-day states: dusk , dawn , day , and night . |
font | String | Defines font family for the style from predefined options. |
The Standard Satellite Style (mapbox://styles/mapbox/standard-satellite
) combines updated satellite imagery and vector layers to offer users improved clarity and detail. Like Standard style, the Satellite Style receives all updates automatically and also supports light presets. Additionally, it introduces two new configurations showRoadsAndTransit
and showPedestrianRoads
. Users can now choose to hide roads, simplifying the map style for a better focus on specific areas or features.
The Standard Satellite style offers 8 configuration properties for developers to change when they import it into their own style:
Property | Type | Description |
---|---|---|
showRoadsAndTransit | Bool | Shows and hides all roads and transit networks. |
showPedestrianRoads | Bool | Shows and hides all pedestrian roads, paths, trails. |
showPlaceLabels | Bool | Shows and hides place label layers. |
showRoadLabels | Bool | Shows and hides all road labels, including road shields. |
showPointOfInterestLabels | Bool | Shows or hides all POI icons and text. |
showTransitLabels | Bool | Shows or hides all transit icons and text. |
lightPreset | String | Switches between 4 time-of-day states: dusk , dawn , day , and night . |
font | String | Defines font family for the style from predefined options. |
Important: Standard satellite style doesn't support theme and show3dObjects configuration. |
Mapbox Standard and Mapbox Standard Satellite are making adding your own data layers easier for you through the concept of slot
s. Slot
s are predefined locations in the style where your layer will be added to (such as on top of existing land layers, but below all labels). To do this, we've added a new slot
property to each Layer
. This property allows you to identify which slot
in the Mapbox Standard your new layer should be placed in. To add custom layers in the appropriate location in the Standard or Standard Satellite style layer stack, we added 3 carefully designed slots that you can leverage to place your layer. These slots will not change, so you can be sure that your own map won't break even as the basemap evolves automatically.
Slot | Description |
---|---|
bottom | Above polygons (land, landuse, water, etc.) |
middle | Above lines (roads, etc.) and behind 3D buildings |
top | Above POI labels and behind Place and Transit labels. Designed to be used with the symbol layers. |
not specified | Above all existing layers in the style |
Set the preferred slot
on the Layer
object before adding it to your map and your layer will be appropriately placed in the Standard style's layer stack. If no slot is specified for a custom layer they are placed at the top of the layer list, providing a location that has highest collision priority compared to all other layers.
+lineLayer(layerId = "line-layer", sourceId = "line-layer") {
lineColor(rgb(255.0, 165.0, 0.0))
slot("middle")
}
For the new Standard or Standard Satellite styles, you can only add layers to these three slots (bottom
, middle
, top
) within the Standard and Standard Satellite style basemaps.
And when a layer type such as background
, fill
, line
, circle
, hillshade
or heatmap
is added to the top
slot in the Standard or Standard Satellite Style, it will be positioned below all labels. This behavior is due to the design of the top
slot in the Standard or Standard Satellite Style, which is primarily intended for use with symbol
layers.
Like to the classic Mapbox styles, you can still use LayerPosition
when importing the Standard or Standard Satellite Style. This method is only applicable to custom layers you have added yourself. If you add two layers to the same slot with a specified layer position the latter will define the order of the layers in that slot.
Standard and Standard Satellite Style are aware of the map lighting configuration using the measure-light
expression, which returns you an aggregated value of your light settings. This returns a value which ranges from 0 (darkest) to 1 (brightest). In darker lights, you make the individual layers light up by using the new *-emissive-stength
expressions, which allow you to add emissive light to different layer types and for example keep texts legible in all light settings. If your custom layers seem too dark, try adjusting the emissive strength of these layers.
Customizing Standard
The underlying design paradigm to the Standard style is different from what you know from the classic core styles. Mapbox manages the basemap experience and surfaces key global styling configurations - in return, you get a cohesive visual experience and an evergreen map, always featuring the latest data, styling and rendering features compatible with your SDK. The configuration options make interactions with the basemap simpler than before. During the beta phase, we are piloting these configurations - we welcome feedback on the beta configurations. If you have feedback or questions about the Standard beta style reach out to: hey-map-design@mapbox.com.
You can customize the color of your Standard or Standard Satellite Style experience by adjusting the 3D light settings. Individual basemap layers and/or color values can’t be adjusted, but all the flexibility offered by the style specification can be applied to custom layers while keeping interaction with the basemap simple through slot
s.
Our existing, classic Mapbox styles (such as Mapbox Streets, Mapbox Light, and Mapbox Satellite Streets) and any custom styles you have built in Mapbox Studio will still work like they do in v10, so no changes are required.
Style Imports
To work with styles like Mapbox Standard or Standard Satellite, we've introduced new Style APIs that allow you to import other styles into the main style you display to your users. These styles will be imported by reference, so updates to them will be reflected in your main style without additional work needed on your side. For example, imagine you have style A and style B. The Style API will allow you to import A into B. Upon importing, you can set configurations that apply to A and adjust them at runtime. The configuration properties for the imported style A will depend on what the creator of style A chooses to be configurable. For the Standard style, 6 configuration properties are available for setting lighting, fonts, and label display options (see The Mapbox Standard Style section above).
To import a style, you should add an "imports" section to your Style JSON. In the above example, you would add this "imports" section to your Style JSON for B to import style A and set various configurations such as Montserrat
for the font
and dusk
for the lightPreset
.
...
"imports": [
{
"id": "A",
"url": "STYLE_URL_FOR_A",
"config": {
"font": "Montserrat",
"lightPreset": "dusk",
"theme": "faded",
"show3dObjects: true,
"showPointOfInterestLabels": true,
"showTransitLabels": false,
"showPlaceLabels": true,
"showRoadLabels": false
}
}
],
...
For a full example of importing a style, take a look at our Standard Style Example. This example imports the Standard style into another style Real Estate New York.
We've introduced new APIs on the Style
object so you can work with these features:
style.styleImports
, which returns all the styles you have imported into your main stylestyle.removeStyleImport()
, which removes the style import with the passed Idstyle.getStyleImportSchema()
, which returns the full schema describing the style import with the passed Idstyle.getStyleImportConfigProperties()
, which returns all the configuration properties of the style import with the passed Idstyle.getStyleImportConfigProperty()
, which returns the specified configuration property of the style import with the passed Idstyle.setStyleImportConfigProperties()
, which sets all the configuration properties of the style import with the passed Idstyle.setStyleImportConfigProperty()
, which sets the specified configuration property of the style import with the passed Id
Besides modifying the configuration properties of the imported styles, you can add your own layers to the imported style through the concept of slot
s. Slot
s are predefined locations in the imported style where your layer will be added to (such as on top of existing land layers, but below all labels). To do this, we've added a new slot
property to each Layer
. This property allows you to identify which slot
in the imported style your new layer should be placed in.
+lineLayer(layerId = "line-layer", sourceId = "line-layer") {
lineColor(rgb(255.0, 165.0, 0.0))
slot("middle")
}
For more information, see The Mapbox Standard Style section above.
Migration steps
1. Update dependencies
Update your app's dependencies to use the latest version of the Mapbox Maps SDK for Android.
dependencies {
implementation 'com.mapbox.maps:android:11.0.0'
}
2. Replace deprecated APIs
Check for deprecated APIs in your code and replace them with the recommended alternatives. Deprecated APIs may be removed in future releases.
2.1 Deprecating MapboxMap.loadStyle methods
The following methods have been deprecated and will be removed in the next major version:
fun loadStyleUri(styleUri: String, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
fun loadStyleUri(styleUri: String, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
fun loadStyleUri(styleUri: String, onStyleLoaded: Style.OnStyleLoaded? = null)
fun loadStyleUri(styleUri: String)
fun loadStyleJson(styleJson: String, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
fun loadStyleJson(styleJson: String, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
fun loadStyleJson(styleJson: String, onStyleLoaded: Style.OnStyleLoaded? = null)
fun loadStyleJson(styleJson: String)
fun loadStyle(styleExtension: StyleContract.StyleExtension, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
The following functions are introduced to load the style:
// to load the style both from URI or JSON
@JvmOverloads
fun loadStyle(
style: String,
onStyleLoaded: Style.OnStyleLoaded? = null,
)
// to load the style using Style DSL
@JvmOverloads
fun loadStyle(
styleExtension: StyleContract.StyleExtension,
onStyleLoaded: Style.OnStyleLoaded? = null,
)
Important notes:
- When using
loadStyle(style: String, onStyleLoaded: Style.OnStyleLoaded? = null)
string is first checked if it is a valid URI, and if not - it will be treated as a JSON. - Parameter
onMapLoadErrorListener
fromloadStyle
was removed as it was not covering all the map / style loading errors. If you need to listen to those errors, you have to register a specific listener in advance, for exampleOnMapLoadErrorListener
should now be registered withMapboxMap.subscribeMapLoadingError
; you could also subscribe to other error / warning events likeMapboxMap.subscribeStyleImageMissing
orMapboxMap.subscribeStyleImageRemoveUnused
. - Parameter
styleTransitionOptions
fromloadStyle
was removed. To applystyleTransitionOptions
, you should use more granular overloadedloadStyle
takingStyleContract.StyleExtension
and add transition options in the DSL block:
mapboxMap.loadStyle(
style(Style.DARK) {
+transition {
duration(100L)
enablePlacementTransitions(false)
}
// other runtime styling
}
)
Related minor breaking change: renamed StyleContract.StyleExtension.styleUri
-> StyleContract.StyleExtension.style
as this property could now return both URI and JSON:
mapboxMap.loadStyle(style(styleUri = Style.DARK))
// should be replaced with
mapboxMap.loadStyle(style(style = Style.DARK))
2.2 Deprecating event listener APIs
All Map
events have become serializable, which brings type-safety and eliminates deserialization errors. We have deprecated traditional listener-based event API (for example MapboxMap.add<EVENT>Listener()
and MapboxMap.remove<EVENT>Listener()
) and modified observable event APIs to subscribe
dedicated events using MapboxMap.subscribe<EVENT>
.
The following methods have been deprecated in favor of subscribe<EVENT>
methods and will be removed in the next major version. The full list is:
fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
fun addOnMapIdleListener(onMapIdleListener: OnMapIdleListener)
fun removeOnMapIdleListener(onMapIdleListener: OnMapIdleListener)
fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
fun addOnMapLoadedListener(onMapLoadedListener: OnMapLoadedListener)
fun removeOnMapLoadedListener(onMapLoadedListener: OnMapLoadedListener)
fun addOnRenderFrameStartedListener(onRenderFrameStartedListener: OnRenderFrameStartedListener)
fun removeOnRenderFrameStartedListener(onRenderFrameStartedListener: OnRenderFrameStartedListener)
fun addOnRenderFrameFinishedListener(onRenderFrameFinishedListener: OnRenderFrameFinishedListener)
fun removeOnRenderFrameFinishedListener(onRenderFrameFinishedListener: OnRenderFrameFinishedListener)
fun addOnSourceAddedListener(onSourceAddedListener: OnSourceAddedListener)
fun removeOnSourceAddedListener(onSourceAddedListener: OnSourceAddedListener)
fun addOnSourceDataLoadedListener(onSourceDataLoadedListener: OnSourceDataLoadedListener)
fun removeOnSourceDataLoadedListener(onSourceDataLoadedListener: OnSourceDataLoadedListener)
fun addOnSourceRemovedListener(onSourceRemovedListener: OnSourceRemovedListener)
fun removeOnSourceRemovedListener(onSourceRemovedListener: OnSourceRemovedListener)
fun addOnStyleDataLoadedListener(onStyleDataLoadedListener: OnStyleDataLoadedListener)
fun removeOnStyleDataLoadedListener(onStyleDataLoadedListener: OnStyleDataLoadedListener)
fun addOnStyleLoadedListener(onStyleLoadedListener: OnStyleLoadedListener)
fun removeOnStyleLoadedListener(onStyleLoadedListener: OnStyleLoadedListener)
fun addOnStyleImageMissingListener(onStyleImageMissingListener: OnStyleImageMissingListener)
fun removeOnStyleImageMissingListener(onStyleImageMissingListener: OnStyleImageMissingListener)
fun addOnStyleImageUnusedListener(onStyleImageUnusedListener: OnStyleImageUnusedListener)
fun removeOnStyleImageUnusedListener(onStyleImageUnusedListener: OnStyleImageUnusedListener)
The following APIs are introduced to subscribe to events:
fun subscribeCameraChanged(cameraChangedCallback: CameraChangedCallback): Cancelable
fun subscribeMapIdle(mapIdleCallback: MapIdleCallback): Cancelable
fun subscribeMapLoadingError(mapLoadingErrorCallback: MapLoadingErrorCallback): Cancelable
fun subscribeMapLoaded(mapLoadedCallback: MapLoadedCallback): Cancelable
fun subscribeRenderFrameStarted(renderFrameStartedCallback: RenderFrameStartedCallback): Cancelable
fun subscribeRenderFrameFinished(renderFrameFinishedCallback: RenderFrameFinishedCallback): Cancelable
fun subscribeSourceAdded(sourceAddedCallback: SourceAddedCallback): Cancelable
fun subscribeSourceDataLoaded(sourceDataLoadedCallback: SourceDataLoadedCallback): Cancelable
fun subscribeSourceRemoved(sourceRemovedCallback: SourceRemovedCallback): Cancelable
fun subscribeStyleDataLoaded(styleDataLoadedCallback: StyleDataLoadedCallback): Cancelable
fun subscribeStyleLoaded(styleLoadedCallback: StyleLoadedCallback): Cancelable
fun subscribeStyleImageMissing(styleImageMissingCallback: StyleImageMissingCallback): Cancelable
fun subscribeStyleImageRemoveUnused(styleImageRemoveUnusedCallback: StyleImageRemoveUnusedCallback): Cancelable
fun subscribeResourceRequest(resourceRequestCallback: ResourceRequestCallback): Cancelable
Note: To unsubscribe, use the returned Cancelable
object.
For convenience, MapboxMap
methods returning Flow
of events were introduced: cameraChangedEvents
, mapIdleEvents
, sourceAddedEvents
, sourceRemovedEvents
, sourceDataLoadedEvents
,
styleImageMissingEvents
, styleImageRemoveUnusedEvents
, renderFrameStartedEvents
, renderFrameFinishedEvents
, resourceRequestEvents
.
Event listeners have been deprecated and replaced with callbacks. Callbacks invoke run
method that will return data associated with the specific event.
v10 | v11 |
---|---|
OnCameraChangeListener | CameraChangedCallback |
OnMapIdleListener | MapIdleCallback |
OnMapLoadErrorListener | MapLoadingErrorCallback |
OnMapLoadedListener | MapLoadedCallback |
OnRenderFrameStartedListener | RenderFrameStartedCallback |
OnRenderFrameFinishedListener | RenderFrameFinishedCallback |
OnSourceAddedListener | SourceAddedCallback |
OnSourceDataLoadedListener | SourceDataLoadedCallback |
OnSourceRemovedListener | SourceRemovedCallback |
OnStyleDataLoadedListener | StyleDataLoadedCallback |
OnStyleLoadedListener | StyleLoadedCallback |
OnStyleImageMissingListener | StyleImageMissingCallback |
OnStyleImageUnusedListener | StyleImageRemoveUnusedCallback |
2.3 Image utilities
- Added
ImageExtensionImpl.Builder(imageId, image)
,ImageExtensionImpl.Builder(imageId, bitmap)
constructors and deprecatedImageExtensionImpl.Builder(imageId)
,ImageExtensionImpl.Builder.image(image)
,ImageExtensionImpl.Builder.bitmap(bitmap)
.
3. Check for breaking changes
The following are breaking changes that may affect your app:
3.1 Location API
MapView.location2
has been removed and the following methodspuckBearingEnabled
,showAccuracyRing
,accuracyRingColor
,accuracyRingBorderColor
were moved toMapView.location
.LocationConsumer2
has been dropped in favor ofLocationConsumer
.PuckBearingSource
was renamed toPuckBearing
:mapbox_locationComponentPuckBearingSource
was renamed tomapbox_locationComponentPuckBearing
.MapView.location2.puckBearingSource
will becomeMapView.location.puckBearing
.
MapView.location.puckBearingEanbled
is nowfalse
by default.LocationConsumer
interface was extended withonError
allowing to handle location errors.LocationConsumer.onAccuracyRadiusUpdated
was renamed toLocationConsumer.onHorizontalAccuracyRadiusUpdated
.
- To keep the 3D model size constant across different zoom levels, platform based
scale-expression
has been removed in favor ofLocationPuck3D.modelScaleMode
API, and the default valueModelScaleMode.VIEWPORT
keeps the 3D model constant across all zoom levels. This introduced a behavioral breaking change, and themodel-scale
property needs to be adjusted to correctly render the puck (we found the adjustment to be around100x
ofmodel-scale
value, but that could vary depending on model properties, etc.).
3.1.1 Using LocationService
instead of LocationEngine
LocationEngine
has been removed. To get a location provider you now have to import thecom.mapbox.common.location.*
packages and use theLocationService
andDeviceLocationProvider
with aLocationObserver
.
First get a DeviceLocationProvider
:
import com.mapbox.common.location.LocationService
import com.mapbox.common.location.LocationServiceFactory
import com.mapbox.common.location.LocationProvider
import com.mapbox.common.location.LocationObserver
val locationService : LocationService = LocationServiceFactory.getOrCreate()
var locationProvider: DeviceLocationProvider? = null
val result = locationService.getDeviceLocationProvider(null)
if (result.isValue) {
locationProvider = result.value!!
} else {
Log.error("Failed to get device location provider")
}
There are also overload versions of getDeviceLocationProvider
that allows to specify DeviceLocationProviderType
and ExtendedLocationProviderParameters
:
LocationService::getDeviceLocationProvider(type: DeviceLocationProviderType,
request: LocationProviderRequest? = null, allowUserDefined: Boolean = true):
Expected<LocationError, DeviceLocationProvider>
LocationService::getDeviceLocationProvider(extendedParameters: ExtendedLocationProviderParameters,
request: LocationProviderRequest? = null):
Expected<LocationError, DeviceLocationProvider>
See the documentation for DeviceLocationProviderType
and ExtendedLocationProviderParameters
for a detailed description of these types.
To receive location updates, create a LocationObserver
and override the onLocationUpdateReceived
function to handle the locations:
val locationObserver = object: LocationObserver {
override fun onLocationUpdateReceived(locations: MutableList<Location>) {
Log.e(TAG, "Location update received: " + locations)
}
}
locationProvider.addLocationObserver(locationObserver);
To stop receiving updates, remove your observer:
locationProvider.removeLocationObserver(locationObserver);
You can register for location updates via a PendingIntent
on the DeviceLocationProvider
:
locationProvider.requestLocationUpdates(myPendingIntent)
locationProvider.removeLocationUpdates(myPendingIntent)
You can also register a LocationObserver
with a Looper
object, the message queue will then be used to implement the callback mechanism:
addLocationObserver(observer: LocationObserver, looper: Looper)
The location provider automatically starts and stops collecting locations based on the amount of subscribers: once the first subscriber is registered, the service starts, and when the last observer is unregistered, the service stops.
If you want to get the last known location, you can do so via the asynchronous LocationProivder.getLastLocation
function. The function returns a Cancelable object which allows cancelling the request if needed:
val lastLocationCancelable = locationProvider.getLastLocation { result ->
result?.let { doSomething(it) }
}
To cancel the request, call
lastLocationCancelable.cancel()
- Compatibility classes
com.mapbox.common.location.compat.*
have been removed.
3.1.2 Common location migration
LocationService::getLastLocation()
changes.
LocationService::getLastLocation()
is replaced by an asynchronous method LocationProvider::getLastLocation()
v10:
LocationService::getLastLocation(): expected<Location, LocationError>
v11:
LocationProvider::getLastLocation(callback: GetLocationCallback): Cancelable
LiveTrackingClient
has been replaced byDeviceLocationProvider
Remove lifecycle mode capabilities from LiveTrackingClient
/DeviceLocationProvider
, LiveTrackingClientSettings::ActivityType
, and LiveTrackingClient::flush()
The explicit start()
and stop()
functions have been removed from the API. DeviceLocationProvider
starts as soon as one observer is attached and stops when all observers are removed.
LocationService::getDeviceLocationProvider
instead ofLocationService::getLiveTrackingClient
Introduce LocationProviderRequest
to replace the Value
setting and simplify API. Add several overloads for getDeviceLocationProvider
to be able to specify custom DeviceLocationProvider
parameters.
v10:
LocationService::getLiveTrackingClient(name: String, capabilities: Value): expected<Location, LocationError>
v11:
LocationService::getDeviceLocationProvider(request: optional<LocationProviderRequest>): Expected<DeviceLocationProvider, LocationError>
LocationService::getDeviceLocationProvider(type: DeviceLocationProviderType,
request: LocationProviderRequest? = null, allowUserDefined: Boolean = true):
Expected<LocationError, DeviceLocationProvider>
LocationService::getDeviceLocationProvider(extendedParameters: ExtendedLocationProviderParameters,
request: LocationProviderRequest? = null):
Expected<LocationError, DeviceLocationProvider>
See the documentation for LocationProviderRequest
, DeviceLocationProviderType
and ExtendedLocationProviderParameters
for a detailed description of these types.
LiveTrackingClientObserver
changes
Rename LiveTrackingClientObserver
to LocationObserver.
Method onLiveTrackingStateChanged()
removed. Method onLocationUpdateReceived()
simplified:
v10:
interface LiveTrackingClientObserver {
fun onLiveTrackingStateChanged(state: LiveTrackingState, error: LocationError?)
fun onLocationUpdateReceived(locationUpdate: Expected<LocationError, List<Location>>)
}
v11:
interface LocationObserver {
fun onLocationUpdateReceived(locations: List<Location>)
}
- Add methods that allows to subscribe to location updates with specific
Looper
orPendingIntent
Extend LocationProvider
to allow registering an observer with Looper
. The observer will be notified through the given Looper
.
addLocationObserver(observer: LocationObserver, looper: Looper)
PendingIntent
can be used to register/unregister for DeviceLocationProvider
location updates.
requestLocationUpdates(pendingIntent: PendingIntent)
removeLocationUpdates(pendingIntent: PendingIntent)
LocationServiceFactory
methods changes
LocationServiceFactory.locationService()
method name changed to LocationServiceFactory.getOrCreate()
LocationServiceFactory.setUserDefined()
method was removed. It is not possible to set custom LocationService
anymore but possible to set custom DeviceLocationProvider
with LocationService::setUserDefinedDeviceLocationProviderFactory()
.
3.2. ResourceOptions
and ResourceOptionsManager
have been removed
There can only be one global Mapbox access token used by the application.
The ResourceOptions
class has been removed. To set options accessToken
, baseURL
, dataPath
,
assetPath
, tileStore
and tileStoreUsageMode
at runtime, use MapboxOptions
and MapboxMapsOptions
objects.
If you were using ResourceOptions
to set the access token and other properties as part of the map
view MapInitOptions
(or MapSnapshotOptions
for the Snapshotter
), you can now call the following
methods before creating the MapView
, MapSurface
or Snapshotter
:
MapboxOptions.accessToken = "your_mapbox_access_token"
MapboxOptions.mapsOptions.tileStore = yourTileStore
MapboxOptions.mapsOptions.tileStoreUsageMode = yourTileStoreUsageMode
You can find an example at MapViewCustomizationActivity.kt
.
The ResourceOptionsManager
class has been removed. To set the default token, define a string resource value:
<resources>
<string name="mapbox_access_token" translatable="false" >your_mapbox_access_token</string>
</resources>
Or you can use MapboxOptions.accessToken
property at runtime.
3.3 Events API
The Observer
interface used to subscribe for observable
events and associated methods MapboxMap.subscribe(observer: Observer, events: List<String>)
and MapboxMap.unsubscribe(observer: Observer, events: List<String>)
have been removed. Use MapboxMap.subscribe<EVENT> : Cancelable
methods to subscribe to the events.