Reputation: 1652
I am attempting to have a GPS location system that will update the users position every second, continuously draw the route they have traveled with Poly-lines, and move the marker to their newest position on every change.
Is there a nice way in Xamarin to remove all markers, but without clearing the previously attached polyline (like map.clear()
would)
Now I understand that I could store the co-ordinates locally and then re-draw them each time, however this could end up being a very long route, and I would rather not have to do this, as eventually there will be a hard limit, where it cannot draw the full route, before the next set of co-ordinates come through and would prefer just to append the newest line to the previously drawn lines, and just move the marker.
Any information on this would be greatly appreciated.
Upvotes: 1
Views: 3047
Reputation: 74094
The Marker
object that that returned from the map AddMarker
method has a .Remove
method.
Casting this returned object as a Maker
will allow you access to the .Remove
method to delete it from the map that it is currently attached to.
Most developers store these returned masker objects in a dictionary/list/... You can either save them as the generic java object that is returned or create a Maker-based generic collection so casting later is not required.
Upvotes: 2
Reputation: 2881
To remove markers without clearing the map through the Clear method you need to keep track of all your markers.
var marker = Map.AddMarker(new MarkerOptions().SetPosition(new LatLng(MyPosition.Latitude, MyPosition.Longitude)));
markerList.Add(marker);
Each marker has a Remove method you can than call by iterating through the markerList.
Upvotes: 0