Skip to content

Instantly share code, notes, and snippets.

@tugcearar
Created September 10, 2020 14:50
Show Gist options
  • Save tugcearar/39924ce439e4bc0ea6b4990895f8189e to your computer and use it in GitHub Desktop.
Save tugcearar/39924ce439e4bc0ea6b4990895f8189e to your computer and use it in GitHub Desktop.
class GeocodeManager
{
public const string ApiKey = "YOUR_API_KEY”
private MainActivity activity;
public GeocodeManager(MainActivity activity)
{
this.activity = activity;
}
public async Task<Site> ReverseGeocode(double lat, double lng)
{
string result = "";
using (var client = new HttpClient())
{
MyLocation location = new MyLocation();
location.Lat = lat;
location.Lng = lng;
var root = new ReverseGeocodeRequest();
root.Location = location;
var settings = new JsonSerializerSettings();
settings.ContractResolver = new LowercaseSerializer();
var json = JsonConvert.SerializeObject(root, Formatting.Indented, settings);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var url = "https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode?key=" + Android.Net.Uri.Encode(ApiKey);
var response = await client.PostAsync(url, data);
result = response.Content.ReadAsStringAsync().Result;
}
return JsonConvert.DeserializeObject<ReverseGeocodeResponse>(result).sites.FirstOrDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment