using System.Device.Location; // Create a GeoCoordinateWatcher object GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); // Start receiving location updates watcher.Start(); // Get the current location GeoCoordinate location = watcher.Position.Location; // Get the latitude and longitude coordinates double latitude = location.Latitude; double longitude = location.Longitude;
using Windows.Devices.Geolocation; // Create a Geolocator object Geolocator locator = new Geolocator(); // Set the desired accuracy locator.DesiredAccuracy = PositionAccuracy.High; // Get the current location Geoposition position = await locator.GetGeopositionAsync(); // Get the latitude and longitude coordinates double latitude = position.Coordinate.Latitude; double longitude = position.Coordinate.Longitude;In this example, we create a Geolocator object and set the desired accuracy to high. We then get the current location using an asynchronous method call and extract the latitude and longitude coordinates. Package library: Windows.Devices.Geolocation