async Task <RequestObj> GetRequest(string path, HttpClient client) { RequestObj jsonObj = null; HttpResponseMessage response = await client.GetAsync(path).ConfigureAwait(false); if (response.IsSuccessStatusCode) { jsonObj = await response.Content.ReadAsAsync <RequestObj>(); } return(jsonObj); }
static async Task RunDataRetrieval(string address) { client.BaseAddress = new Uri(address); try { RequestObj jsonObj = await GetRequest(address, client).ConfigureAwait(false);; route = jsonObj.response.route[0]; } catch (Exception e) { Console.WriteLine(e.Message); } }
async Task RunDataRetrieval(string address) { client.BaseAddress = new Uri(address); try { RequestObj jsonObj = await GetRequest(address, client).ConfigureAwait(false); _lat = jsonObj.results[0].geometry.location.lat; _long = jsonObj.results[0].geometry.location.lng; } catch (Exception e) { Console.WriteLine(e.Message); } }
public static Route Retrieve(string start_address, string end_address, string avoidances) { client = new HttpClient(); GeoCode geo = new GeoCode(); string startCoordinates = geo.Retrieve(start_address); string endCoordinates = geo.Retrieve(end_address); string avoidanceCoords = avoidances; string appId = Keys.HEREAppID; //HERE api ID string appCode = Keys.HEREAppCode; //HERE api Code string baseaddress = "https://route.api.here.com/routing/7.2/calculateroute.json?app_id=" + appId + "&app_code=" + appCode + "&waypoint0=" + startCoordinates + "&waypoint1=" + endCoordinates + "&mode=fastest;pedestrian;traffic:disabled&avoidareas=" + avoidanceCoords; WebRequest requestObject = WebRequest.Create(baseaddress); requestObject.Method = "GET"; HttpWebResponse responseObject = null; responseObject = (HttpWebResponse)requestObject.GetResponse(); string urlResult = null; using (Stream stream = responseObject.GetResponseStream()) { StreamReader sr = new StreamReader(stream); urlResult = sr.ReadToEnd(); sr.Close(); } Route route; RequestObj jsonObj = JsonConvert.DeserializeObject <RequestObj>(urlResult); try { route = jsonObj.response.route[0]; } catch { return(null); } return(route); }