wxr
2023-06-06 592974441a4df95fffd9167c90192da1a390b1c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
            }
        }
    }
}