Advertisement
Beginner .NET MAUI, Device Features & Essentials

How do you get the device's geolocation in MAUI?

Short answer

Use Geolocation.Default.GetLocationAsync (last-known or a fresh request with GeolocationRequest specifying accuracy and timeout). Request location permission first. GetLastKnownLocationAsync is faster but may be stale; GetLocationAsync forces a fix.

Save .NET MAUI mock interview
Advertisement
AModel answer
Use Geolocation.Default.GetLocationAsync (last-known or a fresh request with GeolocationRequest specifying accuracy and timeout). Request location permission first. GetLastKnownLocationAsync is faster but may be stale; GetLocationAsync forces a fix.
var request = new GeolocationRequest(GeolocationAccuracy.Medium,
    TimeSpan.FromSeconds(10));
var loc = await Geolocation.Default.GetLocationAsync(request);
Real-world example
A weather app fetches the user's coordinates to show local conditions after requesting location permission.
Likely follow-ups
  • Last-known vs fresh location? | What permission is required?
Related topics