public async Task ReverseGeocode() { var request = new ReverseGeocoderRequest { Latitude = 58.046733, Longitude = 38.841715 }; var client = new GeocoderClient(apiKey); var response = await client.ReverseGeocode(request); var firstGeoObject = response.GeoObjectCollection.FeatureMember.FirstOrDefault(); var addressComponents = firstGeoObject.GeoObject.MetaDataProperty.GeocoderMetaData.Address.Components; var country = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Country)); var province = addressComponents.LastOrDefault(c => c.Kind.Equals(AddressComponentKind.Province)); var area = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Area)); var city = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Locality)); var street = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Street)); var house = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.House)); Assert.Equal("Россия", country.Name); Assert.Equal("Ярославская область", province.Name); Assert.Equal("городской округ Рыбинск", area.Name); Assert.Equal("Рыбинск", city.Name); Assert.Equal("улица Бородулина", street.Name); Assert.Equal("23", house.Name); }
public async Task RestrictionOfObjectsReturnedByReverseGeocoding() { var request = new ReverseGeocoderRequest { Latitude = 58.046733, Longitude = 38.841715, Kind = AddressComponentKind.Locality }; var client = new GeocoderClient(apiKey); var response = await client.ReverseGeocode(request); var firstGeoObject = response.GeoObjectCollection.FeatureMember.FirstOrDefault(); var addressComponents = firstGeoObject.GeoObject.MetaDataProperty.GeocoderMetaData.Address.Components; var province = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Province)); var city = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Locality)); var street = addressComponents.FirstOrDefault(c => c.Kind.Equals(AddressComponentKind.Street)); Assert.Equal("Центральный федеральный округ", province.Name); Assert.Equal("Рыбинск", city.Name); Assert.Null(street); }