diff --git a/AspNetMonsters.Blazor.Geolocation/AspNetMonsters.Blazor.Geolocation.csproj b/AspNetMonsters.Blazor.Geolocation/AspNetMonsters.Blazor.Geolocation.csproj index 36c3b93..9bd6f9c 100644 --- a/AspNetMonsters.Blazor.Geolocation/AspNetMonsters.Blazor.Geolocation.csproj +++ b/AspNetMonsters.Blazor.Geolocation/AspNetMonsters.Blazor.Geolocation.csproj @@ -13,7 +13,7 @@ true AspNetMonsters.Blazor.Geolocation AspNetMonsters.Blazor.Geolocation - 0.5.0-preview1 + 0.5.0-preview2 ${DefaultItemExcludes};node_modules\** @@ -23,7 +23,7 @@ - + @@ -31,8 +31,12 @@ - - + + + + + + - + \ No newline at end of file diff --git a/AspNetMonsters.Blazor.Geolocation/tsconfig.json b/AspNetMonsters.Blazor.Geolocation/tsconfig.json index bc2fa15..456e31f 100644 --- a/AspNetMonsters.Blazor.Geolocation/tsconfig.json +++ b/AspNetMonsters.Blazor.Geolocation/tsconfig.json @@ -10,7 +10,7 @@ "dom" ], "strict": true, - "outDir": "./content/" + "outDir": "./wwwroot/" }, "exclude": [ "node_modules" diff --git a/README.md b/README.md index 69e9de4..727eb99 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,17 @@ This package provides Blazor applications with access to the browser's [Geolocat 1) In your Blazor app's `Startup.cs`, register the 'LocationService'. + ###### Blazor Server + ```csharp + public void ConfigureServices(IServiceCollection services) + { + ... + services.AddScoped(); + ... + } ``` + ###### 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(); }