0
votes

Ok so I am reading the Microsoft Docs for reverse geocoding

So I am trying to get my city and country code, I am following this

 // 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; 

I am trying to de this in my app, I know that Address, have those 2 properties that I need (https://docs.microsoft.com/en-us/uwp/api/Windows.Services.Maps.MapAddress) Currently my app gets my position, and my coordinates, but how can I get reverse geocode working.

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}";
1

1 Answers

0
votes

Please check finderResult.Status, maybe it is InvalidCredentials. If you can't get the result of reverse geocoding, it is probably because you didn't add the Token of Map service.

Go to here and create a key. Then add it to your app:

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

This is the document about request authentication key.

Best regards.