在我的Windows Phone 8应用程序中,我试图在主页面上使用GetGeopositionAsync来显示一些基于用户位置的项目.
调用GetGeopositionAsync不会在指定的超时内返回,它根本不返回.
我使用的代码很简单:
- Geolocator geolocator = new Geolocator();
- geolocator.DesiredAccuracyInMeters = 50;
- Geoposition geoposition = null;
- try
- {
- geoposition = await geolocator.GetGeopositionAsync(
- maximumAge: TimeSpan.FromMinutes(5),timeout: TimeSpan.FromSeconds(10));
- }
- catch (UnauthorizedAccessException ex)
- {
- // location services disabled or other error
- // user should setup his location
- }
我找到的解决方案是为GeoCoordinateWatcher创建一个异步包装,似乎工作正常.
但是对于我的解决方案我并不太自信,我更喜欢使用GetGeopositionAsync,它看起来像在WP8中获得设备位置的推荐方式.
更新:其他人报告相同的行为:
http://social.msdn.microsoft.com/forums/en-us/wpdevelop/thread/ff166fac-b423-4428-abd8-610bf0102fc0