();
+ ...
+ }
```
+ ###### Blazor WebAssembly
+ ```csharp
public void ConfigureServices(IServiceCollection services)
{
...
@@ -21,9 +31,43 @@ This package provides Blazor applications with access to the browser's [Geolocat
}
```
+1) Add the link to the Location.js script in:
+
+ - _Host.cshtml for Blazor Server
+ - index.html for Blazor WebAssembly
+
+ ```html
+
+ ```
1) Now you can inject the LocationService into any Blazor page and use it like this:
+ ###### Blazor Server
+ Call the LocationService in the OnAfterRenderAsync method
+ ```
+ @using AspNetMonsters.Blazor.Geolocation
+ @inject LocationService LocationService
+ You are here
+
+ Lat: @location?.Latitude
+ Long: @location?.Longitude
+ Accuracy: @location?.Accuracy
+
+
+ @functions
+ {
+ Location location;
+
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ location = await LocationService.GetLocationAsync();
+ StateHasChanged();
+ }
+ }
```
+
+ ###### Blazor WebAssembly
+ Call the LocationService in the OnInitializedAsync method
+ ```
@using AspNetMonsters.Blazor.Geolocation
@inject LocationService LocationService
You are here
@@ -37,7 +81,7 @@ This package provides Blazor applications with access to the browser's [Geolocat
{
Location location;
- protected override async Task OnInitAsync()
+ protected override async Task OnInitializedAsync()
{
location = await LocationService.GetLocationAsync();
}