【发布时间】:2014-03-19 13:06:08
【问题描述】:
我正在开发 windows phone 8 应用程序。
我需要获取用户当前位置的详细信息。
我尝试使用取自MSDN的以下代码
C#:
1 private void OneShotLocationButton_Click(object sender, RoutedEventArgs e)
2 {if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true)
3 {
4 return;
5 }
6 Geolocator geolocator = new Geolocator();
7 geolocator.DesiredAccuracyInMeters = 50;
8 try
9 {
10 Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00");
LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
StatusTextBlock.Text = "location is disabled in phone settings.";
}
//else
{
// something else happened acquring the location
}
}
}
第 10 行出现错误。
'await' 运算符只能在异步方法中使用。考虑使用“async”修饰符标记此方法并将其返回类型更改为“Task”。
我是 Windows Phone 应用程序的新手。现在只有我在 WP8 中开始学习基础知识。
请告诉我如何解决这个问题...
【问题讨论】:
标签: c# xaml windows-phone-8 geolocation location