Persilsoft.Nominatim.Geolocation.Blazor
1.0.4
See the version list below for details.
dotnet add package Persilsoft.Nominatim.Geolocation.Blazor --version 1.0.4
NuGet\Install-Package Persilsoft.Nominatim.Geolocation.Blazor -Version 1.0.4
<PackageReference Include="Persilsoft.Nominatim.Geolocation.Blazor" Version="1.0.4" />
paket add Persilsoft.Nominatim.Geolocation.Blazor --version 1.0.4
#r "nuget: Persilsoft.Nominatim.Geolocation.Blazor, 1.0.4"
// Install Persilsoft.Nominatim.Geolocation.Blazor as a Cake Addin #addin nuget:?package=Persilsoft.Nominatim.Geolocation.Blazor&version=1.0.4 // Install Persilsoft.Nominatim.Geolocation.Blazor as a Cake Tool #tool nuget:?package=Persilsoft.Nominatim.Geolocation.Blazor&version=1.0.4
Persilsoft.Geolocation Blazor
A Geolocation library for Blazor and Razor Components applications.
Example
Get current position
You should register the service that restrieves the user's coordinates:
using ServiceCollectionExtensions;
builder.Services.AddGeolocationService();
Now, you can retrieve the current location of the user.
@page "/geocoder"
@using Persilsoft.Nominatim.Geolocation.Blazor
@inject GeolocationService Geolocation;
<PageTitle>Geolocation Test</PageTitle>
<h1>Geolocation</h1>
<hr />
<button class="btn btn-primary" @onclick=ShowLocation>
Show location
</button>
<div class="row mt-2">
<div class="col-md-6">
<label class="form-label">Latitude:</label>
<input type="text" class="form-control" @bind=latitude disabled />
</div>
<div class="col-md-6">
<label class="form-label">Longitude:</label>
<input type="text" class="form-control" @bind=longitude disabled />
</div>
<p>@message</p>
</div>
@code {
private double latitude;
private double longitude;
private string message = string.Empty;
private async Task ShowLocation()
{
var position = await Geolocation.GetPosition();
if (!position.Equals(default))
{
latitude = position.Latitude;
longitude = position.Longitude;
}
else
{
message = "Location could not be retrieved.";
}
}
}
Reverse Geocoding
If you need to obtain the address of the location, you can use the Reverse Geocoding service.
You should register the Geocoding service:
builder.Services.AddNominatimGeocoderService();
Below, you can modify the previous example to obtain the address.
@page "/geocoder"
@using Persilsoft.Nominatim.Geolocation.Blazor
@using Persilsoft.Nominatim.Geolocation.Blazor.Geocoding
@inject GeolocationService Geolocation
@inject IGeocoder GeocoderService
<PageTitle>Geolocation Test</PageTitle>
<h1>Geolocation</h1>
<hr />
<button class="btn btn-primary" @onclick=ShowLocation>
Show location
</button>
<div class="row mt-2">
<div class="col-md-6">
<label class="form-label">Latitude:</label>
<input type="text" class="form-control" @bind=latitude disabled />
</div>
<div class="col-md-6">
<label class="form-label">Longitude:</label>
<input type="text" class="form-control" @bind=longitude disabled />
</div>
<p>@message</p>
</div>
@if (addressSectionVisible)
{
<section>
<button class="btn btn-warning" @onclick="GetAddress">
Get Address
</button>
<textarea class="form-control mt-2" @bind="AddressDet" disabled>
</textarea>
</section>
}
@code {
private double latitude;
private double longitude;
private string message = string.Empty;
private bool addressSectionVisible;
private string AddressDet = string.Empty;
private async Task ShowLocation()
{
var position = await Geolocation.GetPosition();
if (!position.Equals(default))
{
latitude = position.Latitude;
longitude = position.Longitude;
addressSectionVisible = true;
}
else
{
message = "Location could not be retrieved.";
addressSectionVisible = false;
}
}
private async Task GetAddress()
{
var address = await GeocoderService.GetGeocodingAddressAsync(latitude, longitude);
AddressDet = address.DisplayAddress;
}
}
This package makes use of the Nominatim Geocoding API. For more information, you can visit their site at:
https://nominatim.openstreetmap.org/ui/reverse.html
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.4)
- Microsoft.Extensions.Http (>= 8.0.0)
- Persilsoft.Blazor.JSInterop (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Persilsoft.Nominatim.Geolocation.Blazor:
Package | Downloads |
---|---|
Persilsoft.GeolocationMap.Blazor
This package integrates the retrieval of geographical coordinates and addresses provided by the Persilsoft.Nominatim.Geolocation package, with the mapping capabilities offered by the Persilsoft.Leaflet.Blazor package. |
GitHub repositories
This package is not used by any popular GitHub repositories.