Skip to content

Instantly share code, notes, and snippets.

@zoint
Last active December 30, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoint/7867812 to your computer and use it in GitHub Desktop.
Save zoint/7867812 to your computer and use it in GitHub Desktop.
Basic position changed event handler
private async void PositionChangedHandler(Geolocator sender, PositionChangedEventArgs args)
{
if (args.Position == null || args.Position.Coordinate == null) return;
//save updated coordinates to a property on the class
//can do whatever we want with position, all I need are the coordinates
Position = args.Position.Coordinate;
//stop the tracking once we have our desired accuracy in meters
if (args.Position.Coordinate.Accuracy < 500)
{
// this implicitly stops the tracking operation
_geolocator.PositionChanged -= PositionChangedHandler;
//could raise an event here to let the UI thread know we have a position
//of the desired accuracy at this point.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment