xxxxx

windows10 uwp获取设备当前地理位置(经纬度)

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 geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };
            var position = await geolocator.GetGeopositionAsync();
            return position;   
        }
    }
}

实例化: 

var position = await LocationManager.GetPosition();

通过position.Coordinate.Longitude,position.Coordinate.Latitude属性获得经纬度。

posted @ 2017-09-23 16:01  St4ndAlone  阅读(699)  评论(0编辑  收藏  举报
i still love you