ResolveCountryAndCityNameAsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Tuple<string, string, string, string>> ResolveCountryAndCityNameAsync(double latitude, double longitude, string appName) | |
{ | |
var lat = latitude.ToString(CultureInfo.InvariantCulture).Replace(",", "."); | |
var lon = longitude.ToString(CultureInfo.InvariantCulture).Replace(",", "."); | |
var requestUri = $"http://nominatim.openstreetmap.org/reverse?format=xml&zoom=18&lat={lat}&lon={lon}&application={appName}"; | |
var client = new HttpClient(); | |
var resTask = client.GetStringAsync(requestUri); | |
var res = await resTask; | |
var resultDocument = XDocument.Parse(res); | |
var addressElement = resultDocument.Root.Element("addressparts"); | |
var city = addressElement.Element("city").Value; | |
var country = addressElement.Element("country").Value; | |
var postalCode = addressElement.Element("postcode").Value; | |
var state = addressElement.Element("state").Value; | |
var result = new Tuple<string, string, string, string>(country, city, postalCode, state); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment