Plugin.Maui.GeoLocator
1.0.3
See the version list below for details.
dotnet add package Plugin.Maui.GeoLocator --version 1.0.3
NuGet\Install-Package Plugin.Maui.GeoLocator -Version 1.0.3
<PackageReference Include="Plugin.Maui.GeoLocator" Version="1.0.3" />
<PackageVersion Include="Plugin.Maui.GeoLocator" Version="1.0.3" />
<PackageReference Include="Plugin.Maui.GeoLocator" />
paket add Plugin.Maui.GeoLocator --version 1.0.3
#r "nuget: Plugin.Maui.GeoLocator, 1.0.3"
#:package Plugin.Maui.GeoLocator@1.0.3
#addin nuget:?package=Plugin.Maui.GeoLocator&version=1.0.3
#tool nuget:?package=Plugin.Maui.GeoLocator&version=1.0.3
Plugin.Maui.GeoLocator
A .NET MAUI plugin for Android and iOS that provides:
- On-demand location retrieval
- Start / stop location tracking
- Reverse geocoding
- Optional logging
Install
Package: https://www.nuget.org/packages/Plugin.Maui.GeoLocator
dotnet add package Plugin.Maui.GeoLocator
Or reference the project:
<ProjectReference Include="..\src\Plugin.Maui.GeoLocator\Plugin.Maui.GeoLocator.csproj" />
Host app setup
Android
Declare location permissions in Platforms/Android/AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
iOS
Add usage descriptions to Platforms/iOS/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs your location to show where you are.</string>
For background tracking, also add always-authorization text and the location background mode.
Register the plugin
builder
.UseMauiApp<App>()
.UseGeoLocator(options =>
{
options.EnableLogging = true;
});
Resolve IGeoLocator from dependency injection, or use GeoLocator.Current.
Usage
On-demand location
var location = await GeoLocator.Current.GetCurrentLocationAsync(new LocationRequest
{
Accuracy = LocationAccuracy.Best,
Timeout = TimeSpan.FromSeconds(20)
});
Last cached fix:
var last = await GeoLocator.Current.GetLastKnownLocationAsync();
Start and stop tracking
var locator = GeoLocator.Current;
locator.LocationChanged += (_, e) =>
{
var position = e.Location;
};
locator.LocationError += (_, e) =>
{
Console.WriteLine(e.Message);
};
await locator.StartTrackingAsync(new TrackingOptions
{
Accuracy = LocationAccuracy.High,
MinimumTime = TimeSpan.FromSeconds(2),
MinimumDistanceMeters = 5
});
await locator.StopTrackingAsync();
Reverse geocoding
var addresses = await GeoLocator.Current.ReverseGeocodeAsync(
latitude: 47.6062,
longitude: -122.3321);
foreach (var address in addresses)
Console.WriteLine(address.FormattedAddress);
Logging
GeoLocator.Current.EnableLogging(true);
GeoLocator.Current.EnableLogging(true, new DebugGeoLocatorLogger());
GeoLocator.Current.EnableLogging(false);
When UseGeoLocator(options => options.EnableLogging = true) is used, the plugin also writes through ILogger if the host app registered one (for example builder.Logging.AddDebug()).
Sample
samples/GeoLocator.Sample is a MAUI app that exercises all four features. Deploy it to an Android emulator/device or an iOS simulator/device with location enabled.
dotnet build src/Plugin.Maui.GeoLocator/Plugin.Maui.GeoLocator.csproj
dotnet build samples/GeoLocator.Sample/GeoLocator.Sample.csproj -f net10.0-android
Notes
- Tracking is designed for foreground use. Android background tracking requires a host-app foreground service. iOS background tracking requires
AllowBackgroundUpdates = trueplus thelocationbackground mode. - The plugin requests when-in-use location permission at runtime.
net10.0is included so shared code can reference the package. Location APIs throwGeoLocatorException(FeatureNotSupported) on that target.
Support
If this plugin saved you a weekend of native plumbing, consider buying me a coffee. Your support keeps it maintained, documented, and free.
This library stays open source. A coffee helps cover time for bug fixes, new features, and docs.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-android36.0
- Microsoft.Maui.Controls (>= 10.0.20)
-
net10.0-ios26.0
- Microsoft.Maui.Controls (>= 10.0.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.