/// <summary> /// Converts response into an array of results. /// </summary> /// <param name="response">Response of query.</param> /// <returns>Array of result.</returns> public static OnlineMapsBingMapsLocationResult[] GetResults(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response.Substring(1)); OnlineMapsXMLNamespaceManager nsmgr = xml.GetNamespaceManager("x"); string status = xml.Find <string>("//x:StatusDescription", nsmgr); if (status != "OK") { return(null); } List <OnlineMapsBingMapsLocationResult> results = new List <OnlineMapsBingMapsLocationResult>(); OnlineMapsXMLList resNodes = xml.FindAll("//x:Location", nsmgr); foreach (OnlineMapsXML node in resNodes) { results.Add(new OnlineMapsBingMapsLocationResult(node)); } return(results.ToArray()); } catch (Exception exception) { Debug.Log(exception.Message + "\n" + exception.StackTrace); } return(null); }
/// <summary> /// Converts the route obtained by OnlineMapsOpenRouteService, a list of the steps of the route. /// </summary> /// <param name="route">Route obtained by OnlineMapsOpenRouteService.</param> /// <returns>List of OnlineMapsDirectionStep or null.</returns> public static List <OnlineMapsDirectionStep> TryParseORS(string route) { try { OnlineMapsXML xml = OnlineMapsXML.Load(route); OnlineMapsXMLNamespaceManager nsmgr = xml.GetNamespaceManager(); OnlineMapsXML errorNode = xml.Find("//xls:ErrorList/xls:Error", nsmgr); if (!errorNode.isNull) { return(null); } OnlineMapsXMLList instructionNodes = xml.FindAll("//xls:RouteInstruction", nsmgr); List <OnlineMapsDirectionStep> steps = new List <OnlineMapsDirectionStep>(); foreach (OnlineMapsXML node in instructionNodes) { OnlineMapsDirectionStep step = new OnlineMapsDirectionStep(); step.points = new List <Vector2>(); OnlineMapsXML geometry = node.Find("xls:RouteInstructionGeometry", nsmgr); OnlineMapsXML line = geometry[0]; foreach (OnlineMapsXML pointNode in line) { string coordsStr = pointNode.Value(); string[] coords = coordsStr.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); Vector2 coordsV = new Vector2(float.Parse(coords[0]), float.Parse(coords[1])); step.points.Add(coordsV); } step.distance = (int)(node.Find("xls:Distance", nsmgr).A <float>("value") * 1000); step.instructions = node.Find("xls:Instruction", nsmgr).Value(); steps.Add(step); } return(steps); } catch (Exception exception) { Debug.Log("Exception: " + exception.Message + "\n" + exception.StackTrace); } return(null); }