Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 = $"{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