android - Mapbox 未在 Android 模拟器上显示真实位置
问题描述
Mapbox 在我的真实设备(Samsung S8)上显示当前位置没有问题LocationComponent
,但是我尝试了多个模拟器(Pixel 2、3、3XL)和 Android Pie/Q,地图总是显示谷歌总部而不是真实位置:
这是我的代码:
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)
}
片段.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" />
知道为什么它在模拟器上不起作用吗?
这是我用过的模拟器:
解决方案
推荐阅读
- java - 如何确定 PDF 注释在 PDFBox 中是否可见?
- android - 添加两个ontap方法flutter的方法
- reactjs - 如何在 React Js 中使用 Javascript 访问手机屏幕中的网络摄像头
- python - Windows 10 上的 Chromium Edge 91 崩溃
- sql - 在 SQL 中过滤列对
- azure - 无法使用 azure JavaScript 函数和 Key Vault 机密检索 cosmosDB 数据
- azure - 如果我只使用一个小时然后删除它,Azure APIM 会收取多少费用?
- electron - 未知系统错误 -86 使用电子打包器在 Mac 上为 Window 打包电子应用程序
- android - android.database.sqlite.SQLiteException:没有这样的表:国家(代码 1 SQLITE_ERROR)
- github - 在 Markdown 中更改特殊的内联代码样式以阻止代码样式