//Action for Index view public ActionResult Index() { //reset sessions for new route Session["ModeOfTransportation"] = null; Session["rvm"] = null; //pass API Keys to view ViewBag.Gcode = ConfigReaderDAL.ReadSetting("gcode_key"); ViewBag.Gmap = ConfigReaderDAL.ReadSetting("gmaps_key"); return(View()); }
/// <summary> /// Method to Call Routing API from here.com that generates route /// from users start and endpoint while avoiding areas of bad AQI /// </summary> /// <param name="startPoint">Long/Lat of start point</param> /// <param name="endPoint">Long/Lat of end point</param> /// <param name="avoidTopLeftCoordinates">Long/Lat of top left corner of square to avoid</param> /// <param name="avoidBottomRightCoordinates">Long/Lat of bottom right corner of square to avoid</param> /// <returns> A list of coordinates for route</returns> public static Route GetRoute(string startPoint, string endPoint, List <Sensor> sensorsToAvoid = null, string mode = "pedestrian") { Route route = new Route(); route.ModeOfTransportation = mode; string AppCode = ConfigReaderDAL.ReadSetting("app_code"); string AppId = ConfigReaderDAL.ReadSetting("app_id"); string URL = $"https://route.api.here.com/routing/7.2/calculateroute.json?app_id={AppId}&app_code={AppCode}&waypoint0=geo!{startPoint}&waypoint1=geo!{endPoint}&mode=fastest;{mode};traffic:disabled"; if (sensorsToAvoid != null) { URL += "&avoidareas="; for (int i = 0; i < sensorsToAvoid.Count; i++) { string sensor = sensorsToAvoid[i].BoundingBox.NorthWest.Latitude; sensor += "," + sensorsToAvoid[i].BoundingBox.NorthWest.Longitude; sensor += ";"; sensor += sensorsToAvoid[i].BoundingBox.SouthEast.Latitude; sensor += "," + sensorsToAvoid[i].BoundingBox.SouthEast.Longitude; if (i != sensorsToAvoid.Count - 1) { sensor += "!"; } URL += sensor; } } URL += "&routeattributes=shape"; string APIText = APICall(URL); route.RouteCoordinates = GetCoordinates(APIText); route.TotalTravelTime = GetTotalTravelTime(APIText); route.TotalDistance = GetTotalDistance(APIText); route.Maneuvers = GetManeuvers(APIText); return(route); }