![](/img/trans.png)
[英]How to update the blue dot marker for current location in MapView in Android
[英]How to dynamically update the location of the marker on mapbox in android?
我使用MapBox開發地圖應用程序,我的服務器將返回一些經緯度數據,我需要通過緯度和經度更新標記位置
所以我的代碼是這樣的:
override fun updateDroneLocationResult(drone:Drone) {
var latLng = LatLng(drone.latitude, drone.longitude)
droneMaker = map.addMarker(MarkerOptions().position(latLng))
map.updateMarker(droneMaker!!)
}
但是功能“ updateMarker”無法正常工作,我不知道哪里出了問題。 我該怎么辦?
您不是在更新現有標記,而是每次都添加新標記。 如果要更新現有的,請執行以下操作:
if(mCurrLocationMarker!=null){
mCurrLocationMarker.setPosition(latLng);
}else{
mCurrLocationMarker = map.addMarker(new MarkerOptions()
.position(latLng);
}
另外,如果您想將相機導航或移動到該標記,也可以調用:
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
希望這會幫助你。
我解決了我的問題,這是模擬器的問題,物理電話沒有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.