/// <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 response into an array of results. /// </summary> /// <param name="response">Response of query.</param> /// <returns>Array of result.</returns> public static OnlineMapsOSMNominatimResult[] GetResults(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response); bool isReverse = xml.name == "reversegeocode"; OnlineMapsXMLList resNodes = xml.FindAll(isReverse? "//result" : "//place"); if (resNodes.count == 0) { return(null); } List <OnlineMapsOSMNominatimResult> results = new List <OnlineMapsOSMNominatimResult>(); foreach (OnlineMapsXML node in resNodes) { OnlineMapsOSMNominatimResult result = new OnlineMapsOSMNominatimResult(node, isReverse); OnlineMapsXML adNode = isReverse ? xml["addressparts"] : node; if (!adNode.isNull) { result.LoadAddressDetails(adNode); } results.Add(result); } return(results.ToArray()); } catch (Exception exception) { Debug.Log("Can not get a result.\n" + exception.Message + "\n" + exception.StackTrace); } return(null); }
/// <summary> /// Converts response into an array of results. /// </summary> /// <param name="response">Response of Google API.</param> /// <returns>Array of result.</returns> public static OnlineMapsGooglePlacesAutocompleteResult[] GetResults(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response); string status = xml.Find <string>("//status"); if (status != "OK") { return(null); } List <OnlineMapsGooglePlacesAutocompleteResult> results = new List <OnlineMapsGooglePlacesAutocompleteResult>(); OnlineMapsXMLList resNodes = xml.FindAll("//prediction"); foreach (OnlineMapsXML node in resNodes) { results.Add(new OnlineMapsGooglePlacesAutocompleteResult(node)); } return(results.ToArray()); } catch (Exception exception) { Debug.Log(exception.Message + "\n" + exception.StackTrace); } return(null); }
/// <summary> /// Converts response into an array of results. /// </summary> /// <param name="response">Response of Google API.</param> /// <param name="nextPageToken"> /// Contains a token that can be used to return up to 20 additional results.\n /// A next_page_token will not be returned if there are no additional results to display.\n /// The maximum number of results that can be returned is 60.\n /// There is a short delay between when a next_page_token is issued, and when it will become valid. /// </param> /// <returns>Array of result.</returns> public static OnlineMapsGooglePlacesResult[] GetResults(string response, out string nextPageToken) { nextPageToken = null; try { OnlineMapsXML xml = OnlineMapsXML.Load(response); string status = xml.Find <string>("//status"); if (status != "OK") { return(null); } nextPageToken = xml.Find <string>("//next_page_token"); OnlineMapsXMLList resNodes = xml.FindAll("//result"); List <OnlineMapsGooglePlacesResult> results = new List <OnlineMapsGooglePlacesResult>(resNodes.count); foreach (OnlineMapsXML node in resNodes) { results.Add(new OnlineMapsGooglePlacesResult(node)); } return(results.ToArray()); } catch (Exception exception) { Debug.Log(exception.Message + "\n" + exception.StackTrace); } return(null); }
/// <summary> /// Constructor of OnlineMapsGooglePlaceDetailsResult. /// </summary> /// <param name="node">Place node from response.</param> public OnlineMapsGooglePlaceDetailsResult(OnlineMapsXML node) { this.node = node; formatted_address = node.Get("formatted_address"); formatted_phone_number = node.Get("formatted_phone_number"); OnlineMapsXML locationNode = node.Find("geometry/location"); if (!locationNode.isNull) { location = new Vector2(locationNode.Get <float>("lng"), locationNode.Get <float>("lat")); } icon = node.Get("icon"); id = node.Get("id"); international_phone_number = node.Get("international_phone_number"); name = node.Get("name"); OnlineMapsXMLList photosList = node.FindAll("photo"); photos = new OnlineMapsGooglePlacesResult.Photo[photosList.count]; for (int i = 0; i < photosList.count; i++) { photos[i] = new OnlineMapsGooglePlacesResult.Photo(photosList[i]); } place_id = node.Get <string>("place_id"); price_level = node.Get("price_level", -1); rating = node.Get <float>("rating"); reference = node.Get("reference"); OnlineMapsXMLList typeNode = node.FindAll("type"); types = new string[typeNode.count]; for (int i = 0; i < typeNode.count; i++) { types[i] = typeNode[i].Value(); } url = node.Get("url"); utc_offset = node.Get("utc_offset"); vicinity = node.Get("vicinity"); website = node.Get("website"); }
/// <summary> /// Converts the route obtained by OnlineMapsFindDirection, to array of list of the steps of the route. /// </summary> /// <param name="route">Route obtained by OnlineMapsFindDirection.</param> /// <returns>Array of list of OnlineMapsDirectionStep or null.</returns> public static List <OnlineMapsDirectionStep>[] TryParseWithAlternatives(string route) { try { OnlineMapsXML xml = OnlineMapsXML.Load(route); OnlineMapsXML direction = xml.Find("//DirectionsResponse"); if (direction.isNull) { return(null); } string status = direction.Get <string>("status"); if (status != "OK") { return(null); } OnlineMapsXMLList routes = direction.FindAll("route"); List <OnlineMapsDirectionStep>[] result = new List <OnlineMapsDirectionStep> [routes.count]; for (int i = 0; i < routes.count; i++) { OnlineMapsXMLList legNodes = routes[i].FindAll("leg"); if (legNodes == null || legNodes.count == 0) { continue; } List <OnlineMapsDirectionStep> steps = new List <OnlineMapsDirectionStep>(); foreach (OnlineMapsXML legNode in legNodes) { OnlineMapsXMLList stepNodes = legNode.FindAll("step"); if (stepNodes.count == 0) { continue; } foreach (OnlineMapsXML step in stepNodes) { OnlineMapsDirectionStep navigationStep = new OnlineMapsDirectionStep(step); steps.Add(navigationStep); } } result[i] = steps; } return(result); } catch { } return(null); }
/// <summary> /// Converts the route obtained by OnlineMapsFindDirection, a list of the steps of the route. /// </summary> /// <param name="route">Route obtained by OnlineMapsFindDirection.</param> /// <returns>List of OnlineMapsDirectionStep or null.</returns> public static List <OnlineMapsDirectionStep> TryParse(string route) { try { OnlineMapsXML xml = OnlineMapsXML.Load(route); OnlineMapsXML direction = xml.Find("//DirectionsResponse"); if (direction.isNull) { return(null); } string status = direction.Find <string>("status"); if (status != "OK") { return(null); } OnlineMapsXMLList legNodes = direction.FindAll("route/leg"); if (legNodes == null || legNodes.count == 0) { return(null); } List <OnlineMapsDirectionStep> steps = new List <OnlineMapsDirectionStep>(); foreach (OnlineMapsXML legNode in legNodes) { OnlineMapsXMLList stepNodes = legNode.FindAll("step"); if (stepNodes.count == 0) { continue; } foreach (OnlineMapsXML step in stepNodes) { OnlineMapsDirectionStep navigationStep = new OnlineMapsDirectionStep(step); steps.Add(navigationStep); } } return(steps); } catch { } return(null); }
/// <summary> /// Converts response into an array of results. /// </summary> /// <param name="response">Response of Google API.</param> /// <returns>Array of result.</returns> public static OnlineMapsGoogleElevationResult[] GetResults(string response) { OnlineMapsXML xml = OnlineMapsXML.Load(response); if (xml.isNull || xml.Get <string>("status") != "OK") { return(null); } List <OnlineMapsGoogleElevationResult> rList = new List <OnlineMapsGoogleElevationResult>(); foreach (OnlineMapsXML node in xml.FindAll("result")) { rList.Add(new OnlineMapsGoogleElevationResult(node)); } return(rList.ToArray()); }
/// <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); }
/// <summary> /// Constructor of OnlineMapsFindPlacesResultPhoto. /// </summary> /// <param name="node">Photo node from response</param> public OnlineMapsFindPlacesResultPhoto(OnlineMapsXML node) { try { width = node.Get <int>("width"); height = node.Get <int>("height"); photo_reference = node["photo_reference"].Value(); List <string> html_attributions = new List <string>(); foreach (OnlineMapsXML ha in node.FindAll("html_attributions")) { html_attributions.Add(ha.Value()); } this.html_attributions = html_attributions.ToArray(); } catch (Exception) { } }
/// <summary> /// Constructor of OnlineMapsFindPlaceDetailsResult. /// </summary> /// <param name="node">Place node from response.</param> public OnlineMapsFindPlaceDetailsResult(OnlineMapsXML node) { this.node = node; formatted_address = node.Get("formatted_address"); formatted_phone_number = node.Get("formatted_phone_number"); OnlineMapsXML locationNode = node.Find("geometry/location"); if (!locationNode.isNull) location = new Vector2(locationNode.Get<float>("lng"), locationNode.Get<float>("lat")); icon = node.Get("icon"); id = node.Get("id"); international_phone_number = node.Get("international_phone_number"); name = node.Get("name"); OnlineMapsXMLList photosList = node.FindAll("photos"); photos = new OnlineMapsFindPlacesResultPhoto[photosList.count]; for (int i = 0; i < photosList.count; i++) photos[i] = new OnlineMapsFindPlacesResultPhoto(photosList[i]); place_id = node.Get<string>("place_id"); price_level = node.Get("price_level", -1); rating = node.Get<float>("rating"); reference = node.Get("reference"); OnlineMapsXMLList typeNode = node.FindAll("type"); types = new string[typeNode.count]; for (int i = 0; i < typeNode.count; i++) types[i] = typeNode[i].Value(); url = node.Get("url"); utc_offset = node.Get("utc_offset"); vicinity = node.Get("vicinity"); website = node.Get("website"); }
/// <summary> /// Constructor of OnlineMapsFindPlacesResultPhoto. /// </summary> /// <param name="node">Photo node from response</param> public OnlineMapsFindPlacesResultPhoto(OnlineMapsXML node) { try { width = node.Get<int>("width"); height = node.Get<int>("height"); photo_reference = node["photo_reference"].Value(); List<string> html_attributions = new List<string>(); foreach (OnlineMapsXML ha in node.FindAll("html_attributions")) html_attributions.Add(ha.Value()); this.html_attributions = html_attributions.ToArray(); } catch (Exception) { } }