Skip to content

Instantly share code, notes, and snippets.

@wtuts
Created September 27, 2014 18:50
Show Gist options
  • Select an option

  • Save wtuts/3f6ca6f18abf6347e503 to your computer and use it in GitHub Desktop.

Select an option

Save wtuts/3f6ca6f18abf6347e503 to your computer and use it in GitHub Desktop.
private async void Button_Click(object sender, RoutedEventArgs e)
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
//With this 2 lines of code, the app is able to write on a Text Label the Latitude and the Longitude, given by {{Icode|geoposition}}
geolocation.Text = "GPS:"+geoposition.Coordinate.Latitude.ToString("0.00")+", "+geoposition.Coordinate.Longitude.ToString("0.00");
}
//If an error is catch 2 are the main causes: the first is that you forgot to include ID_CAP_LOCATION in your app manifest.
//The second is that the user doesn't turned on the Location Services
catch (Exception ex)
{
//exception
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment