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

2021-05-12 07:26

阅读:287

标签:ons   cti   window   read   generic   ati   style   threading   system   

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 TaskGetPosition()
        {
            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属性获得经纬度。

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

标签:ons   cti   window   read   generic   ati   style   threading   system   

原文地址:http://www.cnblogs.com/rendan/p/7581469.html


评论


亲,登录后才可以留言!