コード例 #1
0
        public void GetSearchAddressReverseBatch()
        {
            var am = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var q1 = new SearchAddressReverseRequest
            {
                Query = "48.858561,2.294911"
            };
            var q2 = new SearchAddressReverseRequest
            {
                Query  = "47.639765,-122.127896",
                Radius = 5000
            };
            var q3 = new SearchAddressReverseRequest
            {
                Query = "47.621028,-122.348170"
            };

            var req = new SearchAddressReverseRequest[] { q1, q2, q3 };

            var res = am.GetSearchAddressReverse(req).Result;

            Assert.Null(res.ex);

            Assert.NotNull(res.ResultUrl);
        }
コード例 #2
0
        public void GetSearchAddressReverse()
        {
            var am = new AzureMapsToolkit.AzureMapsServices(_KEY);

            var req = new SearchAddressReverseRequest
            {
                Query = "37.337,-121.89"
            };

            var resp = am.GetSearchAddressReverse(req).Result;

            Assert.Null(resp.Error);

            Assert.Equal(1, resp.Result.Summary.NumResults);
        }
コード例 #3
0
        public async Task GetSearchAddressReverse()
        {
            var am = new AzureMapsToolkit.AzureMapsServices(_KEY);

            var req = new SearchAddressReverseRequest
            {
                //Query = "37.337,-121.89",
                Query      = "47.591180, -122.332700",
                EntityType = SearchAddressEntityType.Municipality | SearchAddressEntityType.PostalCodeArea
            };

            var resp = await am.GetSearchAddressReverse(req);

            Assert.Null(resp.Error);

            Assert.Equal(1, resp.Result.Summary.NumResults);
        }
コード例 #4
0
        public async Task <Address> GetAddress(double latitude, double longitude)
        {
            var azureMaps = new AzureMapsToolkit.AzureMapsServices(GetMapKey());

            if (azureMaps == null)
            {
                logger.LogError("Failed to get instance of azuremaps.");
                throw new Exception("Failed to get instance of azuremaps");
            }

            var searchAddressReverseRequest = new SearchAddressReverseRequest();

            searchAddressReverseRequest.Query = $"{latitude},{longitude}";

            logger.LogInformation("Getting address for searchAddressReverseRequest: {0}", JsonSerializer.Serialize(searchAddressReverseRequest));

            var response = await azureMaps.GetSearchAddressReverse(searchAddressReverseRequest).ConfigureAwait(false);

            logger.LogInformation("Response from getting address for searcAddressReverseRequest: {0}", JsonSerializer.Serialize(response));

            if (response.HttpResponseCode != (int)HttpStatusCode.OK && response.HttpResponseCode != 0)
            {
                throw new Exception($"Error getting address: {response}");
            }

            var address = new Address
            {
                StreetAddress = response?.Result?.Addresses[0].Address.StreetNameAndNumber,
                City          = response?.Result?.Addresses[0].Address.Municipality,
                Country       = response?.Result?.Addresses[0].Address.Country,
                Region        = response?.Result?.Addresses[0].Address.CountrySubdivisionName,
                PostalCode    = response?.Result?.Addresses[0].Address.PostalCode,
                County        = response?.Result?.Addresses[0].Address.CountrySecondarySubdivision,
            };

            return(address);
        }
コード例 #5
0
        /// <summary>
        /// There may be times when you need to translate a coordinate (example: 37.786505, -122.3862) into a human understandable street address. Most often this is needed in tracking applications where you receive a GPS feed from the device or asset and wish to know what address where the coordinate is located. This endpoint will return address information for a given coordinate
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public virtual async Task <Response <SearchAddressReverseResponse> > GetSearchAddressReverse(SearchAddressReverseRequest request)
        {
            var res = await ExecuteRequest <SearchAddressReverseResponse, SearchAddressReverseRequest>("https://atlas.microsoft.com/search/address/reverse/json", request);

            return(res);
        }