Mapbox не имеет проблем с отображением текущего местоположения с LocationComponent
на моем реальном устройстве (Samsung S8), однако я пробовал несколько эмуляторов (Pixel 2, 3, 3XL) с Android Pie / Q, и на карте всегда отображается Google Штаб, а не реальное местоположение:
Вот мой код:
class MapFragment : Fragment(), LocationEngineCallback<LocationEngineResult> {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
mapView = view.findViewById(R.id.mapView)
mapView?.onCreate(savedInstanceState)
mapView?.getMapAsync { mapboxMap ->
mapbox = mapboxMap
mapbox.setStyle(Style.MAPBOX_STREETS) {
style -> showUserLocation(style)
}
}
...
@SuppressWarnings("MissingPermission")
private fun showUserLocation(style: Style){
Log.d(TAG, "showUserLocation")
if (PermissionsManager.areLocationPermissionsGranted(homeActivity)){
val locationComponentOptions = LocationComponentOptions.builder(homeActivity)
.bearingTintColor(Color.WHITE)
.accuracyAlpha(0.1f)
.build()
val locationComponentActivationOptions = LocationComponentActivationOptions
.builder(homeActivity, style)
.locationComponentOptions(locationComponentOptions)
.useDefaultLocationEngine(true)
.build()
locationComponent = mapbox.locationComponent
locationComponent?.activateLocationComponent(locationComponentActivationOptions)
locationComponent?.isLocationComponentEnabled = true
locationComponent?.cameraMode = CameraMode.TRACKING
locationComponent?.renderMode = RenderMode.COMPASS
createLocationEngine()
Toast.makeText(homeActivity, "Show location", Toast.LENGTH_LONG).show()
Log.d(TAG, "Show location")
} else {
Toast.makeText(homeActivity, "Permissions not granted", Toast.LENGTH_LONG).show()
}
}
...
@SuppressWarnings("MissingPermission")
private fun createLocationEngine(){
locationEngine = LocationEngineProvider.getBestLocationEngine(homeActivity)
val request = LocationEngineRequest.Builder(LOCATION_INTERVAL)
.setFastestInterval(LOCATION_INTERVAL)
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
.setMaxWaitTime(MAX_WAIT_TIME)
.build()
locationEngine?.getLastLocation(this)
}
fragment.xml
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraZoom="@integer/defaultZoom"
mapbox:mapbox_cameraBearing="34.33"
mapbox:mapbox_cameraZoomMax="@integer/defaultZoom"
mapbox:mapbox_cameraZoomMin="@integer/defaultZoom"
mapbox:mapbox_uiRotateGestures="false"
mapbox:mapbox_uiTiltGestures="false"
mapbox:mapbox_uiScrollGestures="false"
mapbox:mapbox_uiDoubleTapGestures="false" />
Есть идеи, почему он не работает на эмуляторе?
Вот эмуляторы, которые я использовал: