【发布时间】:2019-03-26 05:57:22
【问题描述】:
我正在将 WP8 应用程序迁移到 W8.1,并且我一直在阅读 Geoposition API 不应该更多地用于 W8.1/WP8.1 或更新的操作系统(我在MSDN)。但是我找不到任何示例或想法如何使用 Geopoint API 获取我的当前位置。这是我当前的代码:
public async void GetSinglePositionAsync() {
Geolocator geolocator = null;
Geopoint geoposition = null;
try
{
geolocator = new Windows.Devices.Geolocation.Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
geoposition = await geolocator.GetGeopositionAsync();
double latitude = geoposition.Position.Latitude;
double longitude = geoposition.Position.Longitude;
int altitude = (int)geoposition.Position.Altitude;
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
lblGravity.Text = ex.ToString();
}
}
我最大的问题是当我初始化地理定位变量时,因为它给了我这个错误:“无法将类型 'Windows.Devices.Geolocation.Geoposition' 隐式转换为 'Windows.Devices.Geolocation.Geopoint'” em>,我不知道如何转换它或其他方法来初始化它。
非常感谢您宝贵的时间和帮助。提供的答案也可以在最新的 Windows 上实现。
【问题讨论】:
标签: c# geolocation windows-store-apps windows-8.1