CMS365.BlazoredLocation 9.0.2

dotnet add package CMS365.BlazoredLocation --version 9.0.2
                    
NuGet\Install-Package CMS365.BlazoredLocation -Version 9.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CMS365.BlazoredLocation" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CMS365.BlazoredLocation" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CMS365.BlazoredLocation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CMS365.BlazoredLocation --version 9.0.2
                    
#r "nuget: CMS365.BlazoredLocation, 9.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=CMS365.BlazoredLocation&version=9.0.2
                    
Install CMS365.BlazoredLocation as a Cake Addin
#tool nuget:?package=CMS365.BlazoredLocation&version=9.0.2
                    
Install CMS365.BlazoredLocation as a Cake Tool

BlazoredLocation: A lightweight, easy-to-use library for geolocation services in MAUI apps.

NuGet version GitHub last commit (main) License

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:

alt text

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:

alt text

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

alt text

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

alt text

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

alt text

Open Info.plist in MacCatalyst folder located in BlazoredLocationDemo → Platforms and assign the following permissions

alt text

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

alt text

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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