| | |
| | | using System; |
| | | using System.Threading.Tasks; |
| | | using Xamarin.Essentials; |
| | | //using System; |
| | | //using System.Threading.Tasks; |
| | | //using Xamarin.Essentials; |
| | | |
| | | namespace HDL_ON_Android |
| | | { |
| | | public static class LocationUtils |
| | | { |
| | | public static async Task<Location> GetCurrentLocationAsync() |
| | | { |
| | | try |
| | | { |
| | | var request = new GeolocationRequest(GeolocationAccuracy.Medium); |
| | | var location = await Geolocation.GetLocationAsync(request); |
| | | return location; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 处理异常 |
| | | Console.WriteLine($"获取位置信息失败: {ex.Message}"); |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //namespace HDL_ON_Android |
| | | //{ |
| | | // public static class LocationUtils |
| | | // { |
| | | // public static async Task<Location> GetCurrentLocationAsync() |
| | | // { |
| | | // try |
| | | // { |
| | | // var request = new GeolocationRequest(GeolocationAccuracy.Medium); |
| | | // var location = await Geolocation.GetLocationAsync(request); |
| | | // return location; |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // // 处理异常 |
| | | // Console.WriteLine($"获取位置信息失败: {ex.Message}"); |
| | | // return null; |
| | | // } |
| | | // } |
| | | // } |
| | | //} |