uwp 和 c# 中的反向地理编码

Reverse Geocoding in uwp and c#

好的,我正在阅读有关反向地理编码的 Microsoft 文档

所以我正在尝试获取我的城市和国家/地区代码,我正在关注此

 // The location to reverse geocode.
   BasicGeoposition location = new BasicGeoposition();
   location.Latitude = 47.643;
   location.Longitude = -122.131;
   Geopoint pointToReverseGeocode = new Geopoint(location);

   // Reverse geocode the specified geographic location.
   MapLocationFinderResult result =
         await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

   // If the query returns results, display the name of the town
   // contained in the address of the first result.
   if (result.Status == MapLocationFinderStatus.Success)
   {
      tbOutputText.Text = "town = " +
            result.Locations[0].Address.Town; 

我正在尝试在我的应用程序中删除它,我知道地址具有我需要的那 2 个属性 (https://docs.microsoft.com/en-us/uwp/api/Windows.Services.Maps.MapAddress) 目前我的应用程序获取我的位置和坐标,但我怎样才能使反向地理编码工作。

public MainPage()
        {
            this.InitializeComponent();

          var pos = GetCityData();
        }

        private async Task<string> GetCityData() {
            var citydata = await LocationManager.GetGeopositionAsync();

            BasicGeoposition geoposition = new BasicGeoposition() {
                Latitude = citydata.Coordinate.Point.Position.Latitude, Longitude = citydata.Coordinate.Point.Position.Longitude
            };
            Geopoint geopoint = new Geopoint(geoposition);

            MapLocationFinderResult finderResult = await MapLocationFinder.FindLocationsAtAsync(geopoint);

            return $"{finderResult.Locations[0].Address.Town},{finderResult.Locations[0].Address.CountryCode}";

请检查finderResult.Status,也许是InvalidCredentials。如果你不能得到反向地理编码的结果,可能是因为你没有添加地图服务的Token

转到 here 并创建密钥。然后将其添加到您的应用程序:

public MainPage()
{
    this.InitializeComponent();
    MapService.ServiceToken = "your_token";
}

这是关于请求认证密钥的document

此致。