Я пытаюсь обновить местоположение маркера, установленного при запуске, исходя из моего местоположения. Однако первый маркер размещается, когда приложение открыто, но оно не обновляется. Никаких физических изменений не наблюдается вообще, «Таймер называется» записывается на консоль, поэтому я знаю, что таймер работает. Мой вопрос: Почему он не обновляет местоположение моего маркера через таймер? Также, если есть лучший способ, я открыт для предложений.Обновить позицию маркера карты GPS Xamarin
Вот код, у меня есть:
GoogleMap mMap;
LocationManager _locationManager;
Location _currentLocation;
String _locationProvider;
TextView addresstxt;
MarkerOptions options = new MarkerOptions();
public void OnMapReady(GoogleMap googleMap)// This works as it should on start up.
{
mMap = googleMap;
LatLng latlng = new LatLng(_currentLocation.Latitude, _currentLocation.Longitude);
CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 18);
mMap.MoveCamera(camera);
options.SetPosition(latlng);
options.SetTitle("Vehicle");
options.SetSnippet("Your vehicle is here.");
options.Draggable(false);
mMap.AddMarker(options);
}
private void CountDown()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += OnTimedEvent;
timer.Enabled = true;
}
private void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("Timer called");
mMap.Clear();
LatLng latlng = new LatLng(_currentLocation.Latitude, _currentLocation.Longitude);
CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 18);
mMap.MoveCamera(camera);
MarkerOptions options = new MarkerOptions()
.SetPosition(latlng)
.SetTitle("Vehicle")
.SetSnippet("Your vehicle is here.")
.Draggable(false);
mMap.AddMarker(options);
}