9.0版基本元件

      在〈9.0版基本元件〉中尚無留言

此篇只適用於 9.0版及之前的,不適用於 10.0版

onMapReady

onMapReady方法是MapView必需覆寫的方法。MapView要初始化完成,需要一段很長的時間,當初始化後,就會回調onMapReady方法。所以地圖有任何後續的設定,都必需在此完成。首要的任務,就是將MapboxMap這個地圖先記錄起來。

override fun onMapReady(mapboxMap: MapboxMap) {
this.mapboxMap=mapboxMap
mapboxMap.setStyle(Style.MAPBOX_STREETS, Style.OnStyleLoaded {
var opts = LocationComponentOptions
.builder(context)
.layerBelow("mark")
.bearingTintColor(0xff0000)
.accuracyAlpha(0f)
.build()
var actOpts = LocationComponentActivationOptions.builder(context, mapboxMap.style!!)
.useDefaultLocationEngine(true)
.locationComponentOptions(opts)
.build()
component = mapboxMap.locationComponent
component?.activateLocationComponent(actOpts)
component?.setCameraMode(CameraMode.TRACKING_GPS)
component?.renderMode=RenderMode.GPS
val request = LocationEngineRequest.Builder(MIN_TIME)
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
.setMaxWaitTime(MIN_TIME * 5)
.build()
var engine = LocationEngineProvider.getBestLocationEngine(context)
engine.requestLocationUpdates(request, locationUpdate, context.mainLooper)
component?.locationEngine=engine
component?.isLocationComponentEnabled=true
resetMap()
lineManager= LineManager(this, mapboxMap, it)
initPath(it)
})
}

LocationEngine

用來更新位置的引擎,可以設定最高精準度等設定。另外,當位置有變化時,可以由engine.requestLocationUpdates設定當位置有變化時,要回調的方法。

🔒 更多內容,請登入會員繼續閱讀。

立即登入

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *