AspNetMonsters / Blazor.Geolocation

Blazor interop for browers Geolocation apis
MIT License
91 stars 25 forks source link

Add support for watchPosition #3

Open dpaquette opened 6 years ago

dpaquette commented 6 years ago

The watchPosition method seems useful. We should support it. https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition

dpaquette commented 6 years ago

I got this working on the plane. I will try to get it checked in and published soon

dpaquette commented 6 years ago

This is done. I just need to update the Readme with a sample so people know how to use it

joseftw commented 5 years ago

Hello! Im trying to get the WatchLocation feature to work, but it seems like it never fires, my breakpoint in OnWatchLocationCallback is never hit. Have I missed something obvious? GetLocationAsync works like a charm :)

@functions
{
    private string _position = string.Empty;
    Location _location;

    protected override async Task OnInitAsync()
    {
        await LocationService.WatchLocation(OnWatchLocationCallback);
        _location = await LocationService.GetLocationAsync();
    }

    private void OnWatchLocationCallback(Location obj)
    {
        _position = $"{obj.Latitude} - {obj.Longitude} - {obj.Accuracy}";
    }
}
soend commented 5 years ago

Hello! Im trying to get the WatchLocation feature to work, but it seems like it never fires, my breakpoint in OnWatchLocationCallback is never hit. Have I missed something obvious? GetLocationAsync works like a charm :)

@functions
{
    private string _position = string.Empty;
    Location _location;

    protected override async Task OnInitAsync()
    {
        await LocationService.WatchLocation(OnWatchLocationCallback);
        _location = await LocationService.GetLocationAsync();
    }

    private void OnWatchLocationCallback(Location obj)
    {
        _position = $"{obj.Latitude} - {obj.Longitude} - {obj.Accuracy}";
    }
}

Hello,

Did you end up figuring this out? I tried it also and it only seemed to work when i call the WatchLocation method from OnAfterRenderAsync override. Example:

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await LocationService.WatchLocation(OnWatchLocationCallback);
        StateHasChanged();
    }