![windows10 uwp获取设备当前地理位置(经纬度) windows10 uwp获取设备当前地理位置(经纬度)](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.Devices.Geolocation;//引用此命名空间 namespace SimpleWeather { public class LocationManager { public async static Task< Geoposition >GetPosition() { var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus != GeolocationAccessStatus.Allowed) throw new Exception(); }; var position = await geolocator.GetGeopositionAsync(); return position; } } }
实例化:
var position = await LocationManager.GetPosition();
通过position.Coordinate.Longitude,position.Coordinate.Latitude属性获得经纬度。