I am trying to get current location for WinRT application. But PositionChanged event never gets fired. Any help is highly appreciated !
In Package.appxmanifest, I have enabled Location. My code is below:-
Geolocator geolocator = new Geolocator { ReportInterval = 2000 };
geolocator.DesiredAccuracyInMeters = 100; // specify your range
geolocator.PositionChanged += OnPositionChanged;
private async void OnPositionChanged(Geolocator sender, PositionChangedEventArgs e)
{
if (this.previousLocationState == LocationStates.PopupEmpty && (viewModel.Coordinate == null || viewModel.Coordinate.Latitude != prevGpsCoordinate.Latitude || viewModel.Coordinate.Longitude != prevGpsCoordinate.Longitude))
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
this.viewModel.Coordinate = new GpsCoordinate { Latitude = e.Position.Coordinate.Point.Position.Latitude, Longitude = e.Position.Coordinate.Point.Position.Longitude };
Field.GpsCoordinate gpsCoord = new Field.GpsCoordinate { Latitude = viewModel.Coordinate.Latitude, Longitude = viewModel.Coordinate.Longitude };
CreateMapPin(gpsCoord);
prevGpsCoordinate = this.viewModel.Coordinate;
});
}
}