Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor - User (device) geolocation

I would like to have the option of getting the current user location on my blazor (server) app. I had tried to use two solutions Darnton.Blazor.DeviceInterop and AspNetMonsters.Blazor.Geolocation. With the first one, I had a problem with how to properly use that, the second one after NuGet install break the whole application ... I will be grateful for sharing other solutions, the simpler the better

like image 763
Krzysztof Krysztofczyk Avatar asked Jul 12 '26 23:07

Krzysztof Krysztofczyk


1 Answers

If you install the Blazor Geolocation package you mentioned (Darnton.Blazor.DeviceInterop), you should be able to use the GeolocationService with a one-liner:

CurrentPositionResult = await GeolocationService.GetCurrentPosition();

I've written it all up in more detail if you want to understand what's going on inside:

https://darnton.co.nz/2020/11/29/geolocation-in-blazor/

https://darnton.co.nz/2020/11/30/geolocation-ii-position-updates/

like image 65
Bernard Darnton Avatar answered Jul 18 '26 03:07

Bernard Darnton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!