示例#1
0
        /// <summary>
        /// Retrieves the city, state, and country for a given location.
        /// </summary>
        /// <param name="loc">Location to geocode.</param>
        /// <param name="ct">Cancellation token.</param>
        /// <returns>String name representing the specified location.</returns>
        public async Task <string> GetCityStateCountryAsync(ILocationModel loc, CancellationToken ct)
        {
            // Reverse geocode the specified geographic location.
            var result = await MapLocationFinder.FindLocationsAtAsync(loc?.AsGeoPoint()).AsTask(ct);

            // If the query returns results, display the name of the town
            // contained in the address of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                return(loc.LocationDisplayName = this.ConcatAddressParts(3, result.Locations[0].Address?.Town, result.Locations[0].Address?.Region, result.Locations[0].Address?.Country, result.Locations[0].Address?.Continent));
            }
            else
            {
                return(loc.LocationDisplayName = null);
            }
        }
示例#2
0
        /// <summary>
        /// Retrieves a formatted address for a given location.
        /// </summary>
        /// <param name="loc">Location to geocode.</param>
        /// <returns>String name representing the specified location.</returns>
        public async Task <string> GetAddressAsync(ILocationModel loc, CancellationToken ct)
        {
            // Reverse geocode the specified geographic location.
            var result = await MapLocationFinder.FindLocationsAtAsync(loc?.AsGeoPoint()).AsTask(ct);

            // If the query returns results, display the name of the town
            // contained in the address of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                return(loc.LocationDisplayName = result?.Locations[0].Address?.FormattedAddress);
            }
            else
            {
                return(loc.LocationDisplayName = null);
            }
        }