如何在 UWP 项目中捕获我所在位置的经度和纬度?
how to capture the longitude and latitude of my location in a UWP project?
我想知道如何捕捉我在经度和纬度方面的真实位置,我正在用 C # 创建一个 UWP 项目
谢谢!
您需要使用 GeoLocator class,为此请确保在您的应用程序清单中启用 定位功能 ,然后使用以下代码启用位置。
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();
要获取您在 uwp 中的当前位置,您需要先在项目 package.appxmanifest
文件中添加 <DeviceCapability Name="location"/>
。 UWP 在 Windows.Devices.Geolocation
命名空间中提供了位置 API。
这是描述详细代码过程的official documentation。
这是官方的code sample,其中包含有关使用 MapControl 的大部分场景。
我想知道如何捕捉我在经度和纬度方面的真实位置,我正在用 C # 创建一个 UWP 项目
谢谢!
您需要使用 GeoLocator class,为此请确保在您的应用程序清单中启用 定位功能 ,然后使用以下代码启用位置。
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();
要获取您在 uwp 中的当前位置,您需要先在项目 package.appxmanifest
文件中添加 <DeviceCapability Name="location"/>
。 UWP 在 Windows.Devices.Geolocation
命名空间中提供了位置 API。
这是描述详细代码过程的official documentation。
这是官方的code sample,其中包含有关使用 MapControl 的大部分场景。