-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
LocationHelpers.cs
39 lines (33 loc) · 968 Bytes
/
LocationHelpers.cs
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright(c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
using Windows.Devices.Geolocation;
using Windows.Services.Maps;
namespace Files.App.Helpers
{
public static class LocationHelpers
{
public static async Task<string> GetAddressFromCoordinatesAsync(double? Lat, double? Lon)
{
if (!Lat.HasValue || !Lon.HasValue)
return null;
if (string.IsNullOrEmpty(MapService.ServiceToken))
{
try
{
MapService.ServiceToken = "bingmapskey.secret";
}
catch (Exception)
{
return null;
}
}
BasicGeoposition location = new BasicGeoposition();
location.Latitude = Lat.Value;
location.Longitude = Lon.Value;
Geopoint pointToReverseGeocode = new Geopoint(location);
// Reverse geocode the specified geographic location.
var result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);
return result?.Locations?.FirstOrDefault()?.DisplayName;
}
}
}