/// <summary> /// Constructor. \n /// <strong>Please do not use. </strong>\n /// Use OnlineMapsDirectionStep.TryParse. /// </summary> /// <param name="node">XMLNode of route</param> private OnlineMapsDirectionStep(OnlineMapsXML node) { start = node.GetLatLng("start_location"); end = node.GetLatLng("end_location"); duration = node.Find<int>("duration/value"); instructions = node.Find<string>("html_instructions"); GetStringInstructions(); distance = node.Find<int>("distance/value"); maneuver = node.Find<string>("maneuver"); string encodedPoints = node.Find<string>("polyline/points"); points = OnlineMapsGoogleAPIQuery.DecodePolylinePoints(encodedPoints); }
/// <summary> /// Constructor. \n /// Use OnlineMapsDirectionStep.TryParse. /// </summary> /// <param name="node">XMLNode of route</param> private OnlineMapsDirectionStep(OnlineMapsXML node) { start = node.GetLatLng("start_location"); end = node.GetLatLng("end_location"); duration = node.Find <int>("duration/value"); instructions = node.Find <string>("html_instructions"); GetStringInstructions(); distance = node.Find <int>("distance/value"); maneuver = node.Find <string>("maneuver"); string encodedPoints = node.Find <string>("polyline/points"); points = OnlineMapsUtils.DecodePolylinePoints(encodedPoints); }
/// <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 Google API.</param> /// <returns>Array of result.</returns> public static OnlineMapsGoogleGeocodingResult[] GetResults(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response); string status = xml.Find <string>("//status"); if (status != "OK") { return(null); } List <OnlineMapsGoogleGeocodingResult> results = new List <OnlineMapsGoogleGeocodingResult>(); OnlineMapsXMLList resNodes = xml.FindAll("//result"); foreach (OnlineMapsXML node in resNodes) { results.Add(new OnlineMapsGoogleGeocodingResult(node)); } return(results.ToArray()); } catch (Exception exception) { Debug.Log(exception.Message + "\n" + exception.StackTrace); } return(null); }
private void OnFindLocationComplete(string result) { // Log Google Geocode API response. if (logResponse) { Debug.Log(result); } // Get the coordinates of the first found location. Vector2 position = OnlineMapsGoogleGeocoding.GetCoordinatesFromResult(result); if (position != Vector2.zero) { // Create a new marker at the position of Chicago. if (addMarker) { OnlineMaps.instance.AddMarker(position, "Chicago"); } // Set best zoom if (setZoom) { // Load response XML OnlineMapsXML xml = OnlineMapsXML.Load(result); // Get bounds node OnlineMapsXML bounds = xml.Find("//geometry/viewport"); if (!bounds.isNull) { // Get corners nodes OnlineMapsXML southwest = bounds["southwest"]; OnlineMapsXML northeast = bounds["northeast"]; // Get coordinates from nodes Vector2 sw = OnlineMapsXML.GetVector2FromNode(southwest); Vector2 ne = OnlineMapsXML.GetVector2FromNode(northeast); // Get best zoom Vector2 center; int zoom; OnlineMapsUtils.GetCenterPointAndZoom(new[] { sw, ne }, out center, out zoom); // Set map zoom OnlineMaps.instance.zoom = zoom; } } // Set map position if (setPosition) { OnlineMaps.instance.position = position; } } else { Debug.Log("Oops... Something is wrong."); } }
/// <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> /// Gets the coordinates of the first results from OnlineMapsFindLocation result. /// </summary> /// <param name="response">XML string. The result of the search location.</param> /// <returns>Coordinates - if successful, Vector2.zero - if failed.</returns> public static Vector2 GetCoordinatesFromResult(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response); OnlineMapsXML location = xml.Find("//geometry/location"); if (location.isNull) { return(Vector2.zero); } return(GetVector2FromNode(location)); } catch { } return(Vector2.zero); }
/// <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 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 response into an result object. /// Note: The object may not contain all the available fields.\n /// Other fields can be obtained from OnlineMapsGooglePlaceDetailsResult.node. /// </summary> /// <param name="response">Response of Google API.</param> /// <returns>Result object or null.</returns> public static OnlineMapsGooglePlaceDetailsResult GetResult(string response) { try { OnlineMapsXML xml = OnlineMapsXML.Load(response); string status = xml.Find <string>("//status"); if (status != "OK") { return(null); } return(new OnlineMapsGooglePlaceDetailsResult(xml["result"])); } catch { } return(null); }
/// <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"); }