From fbb47caebcf0a538d1d7fa1e149e5923ff2f44c1 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 9 Jan 2022 11:05:55 +1100 Subject: [PATCH 1/2] Create README.md --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..62a5f53 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# BlazorDeviceInterop +Blazor library for interacting with browser Web APIs. + +Currently offering: + +- A GeolocationService to retrieve the latitude and longitude of your device from the browser. + +## Setup +- Install NuGet package *Darnton.Blazor.DeviceInterop* into your Blazor project +- Add the AddScoped command to your services in the DI container (in Program.cs of your Blazor web project) +``` +builder.Services + .AddScoped() +``` +- In the code section of your Razor page, add a property to GeolocationService, with an inject attribute (so the DI can populate the property at run time) +``` + [Inject] + public IGeolocationService GeolocationService { get; set; } +``` + +## Usage + +Call *await GeolocationService.GetCurrentPosition()* to get your device's current location. + +Example code: + +``` + var currentPositionResult = await GeolocationService.GetCurrentPosition(); + var lat = currentPositionResult.Position.Coords.Latitude; + var lng = currentPositionResult.Position.Coords.Longitude; + var alt = currentPositionResult.Position.Coords.Altitude; + Console.WriteLine($"Current device location is latitude {lat}, longitude {lng}, altitude {alt}."); +``` + +See also: + +- Example code in BlazorDeviceTestRig folder of this github project +- [Geolocation in Blazor](https://darnton.co.nz/2020/11/29/geolocation-in-blazor/) From f2bb2c49eab7641958215e47538e769db2ffccf2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 9 Jan 2022 11:12:16 +1100 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62a5f53..05d58e4 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Example code: Console.WriteLine($"Current device location is latitude {lat}, longitude {lng}, altitude {alt}."); ``` -See also: +## See Also - Example code in BlazorDeviceTestRig folder of this github project - [Geolocation in Blazor](https://darnton.co.nz/2020/11/29/geolocation-in-blazor/)