CMS365.BlazoredLocation
9.0.2
dotnet add package CMS365.BlazoredLocation --version 9.0.2
NuGet\Install-Package CMS365.BlazoredLocation -Version 9.0.2
<PackageReference Include="CMS365.BlazoredLocation" Version="9.0.2" />
<PackageVersion Include="CMS365.BlazoredLocation" Version="9.0.2" />
<PackageReference Include="CMS365.BlazoredLocation" />
paket add CMS365.BlazoredLocation --version 9.0.2
#r "nuget: CMS365.BlazoredLocation, 9.0.2"
#addin nuget:?package=CMS365.BlazoredLocation&version=9.0.2
#tool nuget:?package=CMS365.BlazoredLocation&version=9.0.2
BlazoredLocation: A lightweight, easy-to-use library for geolocation services in MAUI apps.
The BlazoredLocation package simplifies geolocation in MAUI apps, enabling easy access to user coordinates (latitude/longitude) with minimal code. It wraps the Geolocation API for seamless async integration.
Installation
BlazoredLocation is available on NuGet. Use the package manager console in Visual Studio to install it:
Install-Package CMS365.BlazoredLocation
Setup
When you create a project with Blazor hybrid and web app template, you get 3 projects created.
For example:
Install package in all 3 projects.
Add a new interface method in IFormFactor located at BlazoredLocationDemo.Shared.Services
public Task<Geolocation> GetGeolocation();
Dependency Injection for BlazoredLocationDemo.Web
builder.Services.AddScoped<IFormFactor, FormFactor>(); //Chane to AddScoped form AddSingleton
builder.Services.AddScoped<IBrowserLocation, BrowserLocation>();
Implement GetGeolocation in FormFactor located at BlazoredLocationDemo.Web.Services
private readonly IBrowserLocation browserLocation;
public FormFactor(IBrowserLocation browserLocation)
{
this.browserLocation = browserLocation;
}
public async Task<Geolocation> GetGeolocation()
{
Geolocation geolocation = await browserLocation.GetGeolocation();
return geolocation;
}
In the Home.razor or any component where you want to access location, for example
@inject IFormFactor FormFactor //If it is not already there
Create OnAfterRenderAsync If it does not exist and call GetGeolocation()
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
BlazoredLocation.Entities.Geolocation geolocation = await FormFactor.GetBrowserLocation();
}
}
Run the web project and when the home component loads, user will be shown a confirmation popup for location sharing.
For example:
geolocation variable in the OnAfterRenderAsync now has the current location or error If any.
Dependency Injection for BlazoredLocationDemo
builder.Services.AddScoped<IFormFactor, FormFactor>();
builder.Services.AddScoped<IDeviceLocation, DeviceLocation>();
Implement GetGeolocation in FormFactor located at BlazoredLocationDemo.Services
private readonly IDeviceLocation deviceLocation;
public FormFactor(IDeviceLocation deviceLocation)
{
this.deviceLocation = deviceLocation;
}
public async Task<BlazoredLocation.Entities.Geolocation> GetGeolocation()
{
BlazoredLocation.Entities.Geolocation geolocation = await deviceLocation.GetDeviceLocation(true);
return geolocation;
}
Running in Windows Machine
Select Windows Machine and run the project.
geolocation variable in the OnAfterRenderAsync now has the current location or error If any.
You can control location settings in "Location privacy settings" in widows
Running in Android Emulator
Open AndroidManifest.xml located in BlazoredLocationDemo → Platforms → Android → Resources and assign following permissions
Up-to-date information is here https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/geolocation?view=net-maui-9.0&tabs=android
Select Android Emulator and run the project, you will see a popup and allow permissions
geolocation variable in the OnAfterRenderAsync now has the current location or error If any.
You can control location settings in Settings in Android device.
Running in IOS Emulator
Open Info.plist in IOS folder located in BlazoredLocationDemo → Platforms and assign the following permissions
Open Info.plist in MacCatalyst folder located in BlazoredLocationDemo → Platforms and assign the following permissions
Up-to-date information https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/geolocation?view=net-maui-9.0&tabs=macios
Select IOS Simulator and run the project, you will see a popup and allow permissions
geolocation is being returned as null, possibly due to Simulator I am using and I don't have physical device to test it. Please test and let me know.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Microsoft.JSInterop (>= 9.0.3)
- Microsoft.Maui.Essentials (>= 9.0.50)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.2 | 127 | 3/30/2025 |
9.0.1 | 116 | 3/27/2025 |
9.0.0-beta | 118 | 3/26/2025 |