Advertisement
Advanced .NET MAUI, Maps & Location

How do you continuously track and display the user's location on a map?

Short answer

Combine Geolocation.Default.GetLocationAsync in a loop or platform continuous-location updates (via a listener) with map recentering. Update a pin/position on the main thread, throttle updates to save battery, and stop tracking when the screen is not visible.

Save .NET MAUI mock interview
Advertisement
AModel answer
Combine Geolocation.Default.GetLocationAsync in a loop or platform continuous-location updates (via a listener) with map recentering. Update a pin/position on the main thread, throttle updates to save battery, and stop tracking when the screen is not visible. For background tracking, use platform location services.
// Poll periodically while the page is active
var loc = await Geolocation.Default.GetLocationAsync(
    new GeolocationRequest(GeolocationAccuracy.Best));
map.MoveToRegion(MapSpan.FromCenterAndRadius(
    new Location(loc.Latitude, loc.Longitude), Distance.FromMeters(200)));
Real-world example
A running app follows the user's position live, recentering the map as they move while throttling updates to conserve battery.
Likely follow-ups
  • How do you save battery while tracking? | What handles background location?
Related topics