【问题标题】:how to capture the longitude and latitude of my location in a UWP project?如何在 UWP 项目中捕获我所在位置的经度和纬度?
【发布时间】:2018-09-21 20:41:44
【问题描述】:

我想知道如何以经度和纬度捕捉我的真实位置,我正在用 C# 创建一个 UWP 项目

谢谢!

【问题讨论】:

标签: c# google-maps uwp location


【解决方案1】:

您需要使用GeoLocator 类,为此请确保在您的应用清单中启用位置功能,然后使用以下代码启用位置。

var geoLocator = new Geolocator();  
geoLocator.DesiredAccuracy = PositionAccuracy.High;  
var pos = await geoLocator.GetGeopositionAsync();  
string latitude = "Latitude: " + pos.Coordinate.Point.Position.Latitude.ToString();  
string longitude = "Longitude: " + pos.Coordinate.Point.Position.Longitude.ToString(); 

【讨论】:

    【解决方案2】:

    要在 uwp 中获取您的当前位置,您需要先在项目 package.appxmanifest 文件中添加 <DeviceCapability Name="location"/>。 UWP 在 Windows.Devices.Geolocation 命名空间中提供了位置 API。 这是official documentation,描述了详细的代码过程。

    这是官方code sample,其中包含有关使用 MapControl 的大部分场景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 2015-09-07
      • 1970-01-01
      相关资源
      最近更新 更多