0
votes

I use MapBox develop a map application, my server will return some latitude and longitude data,I need to update marker location through latitude and longitude

so my code like this:

override fun updateDroneLocationResult(drone:Drone) {
    var latLng = LatLng(drone.latitude, drone.longitude)
    droneMaker = map.addMarker(MarkerOptions().position(latLng))
    map.updateMarker(droneMaker!!)
}

but the function "updateMarker" is not working, I don't know where's wrong. what should I do?

2

2 Answers

0
votes

You are not updating existing marker instead adding new marker each time. If you want to update existing one do something like this:

  if(mCurrLocationMarker!=null){
        mCurrLocationMarker.setPosition(latLng);
    }else{
        mCurrLocationMarker = map.addMarker(new MarkerOptions()
                                .position(latLng);
    }

also if you want to navigate or move the camera to this marker also call:

   map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));

Hope this will help you.

0
votes

I fix my problem, it is the problem with the simulator, I have no problem with the physical phone.