Select to view content in your preferred language

Cancel/Stop RouteTracker

450
2
05-02-2023 05:38 AM
smithse
New Contributor III

Hi all,

I am using the samples from the kit and trying to work out how to "Stop" or "Cancel" the route tracking, when a RouteTracker is used. Starting is not an issue, but for the life of me, cannot see a way to cancel it.

Any suggestions are welcomed!

Regards,
Sean

0 Kudos
2 Replies
FrankKish
Esri Contributor

Hi,

You don't really turn a route tracker object on or off rather, a location data source can pass new locations to a route tracker object. Is is the location data source that is turned "on" or "off"

If you use the RouteTrackerLocationDataSource it takes a route tracker object and a "base" location data source, then internally new incoming locations from the location data source are passed to the route tracker via the TrackLocationAsync method. The same is true if you used your write your own custom location data source class (vs using the RouteTrackerLocationDataSource), but in that case you'd explicitly call the TrackLocationAsync method.

So to "stop" the route tracker you'd stop the base location data source. So for example you can call the map's location display and set "isEnable=False", but if you want to still see the blue dot you'd have to reset the map's location display to a location data source object and enable it.

Examples
// stopping the location data source will stop the route
// tracker from getting new locations and remove blue dot
MyMapView.LocationDisplay.IsEnabled = false;

// stopping the location data source will stop the route
// tracker from getting new locations, so to still show a
// blue dot set the location data source on the map
MyMapView.LocationDisplay.IsEnabled = false;
MyMapView.LocationDisplay.DataSource = new SystemLocationDataSource();
MyMapView.LocationDisplay.IsEnabled = true;

Frank 

0 Kudos
smithse
New Contributor III

Hi Frank,

Thank you for the advice. I must admit, I was thinking about something similar which involved setting a flag which would then be looked at when the location was updated, to determine if the location should be sent to the tracker. I will try out your method as it seems very straightforward.

Cheers,
Sean

0 Kudos