public Leg(OnlineMapsXML node)
        {
            List <Step> steps = new List <Step>();

            foreach (OnlineMapsXML n in node)
            {
                if (n.name == "step")
                {
                    steps.Add(new Step(n));
                }
                else if (n.name == "duration")
                {
                    duration = new TextValue <int>(n);
                }
                else if (n.name == "duration_in_traffic")
                {
                    duration_in_traffic = new TextValue <int>(n);
                }
                else if (n.name == "distance")
                {
                    distance = new TextValue <int>(n);
                }
                else if (n.name == "start_location")
                {
                    start_location = OnlineMapsXML.GetVector2FromNode(n);
                }
                else if (n.name == "end_location")
                {
                    end_location = OnlineMapsXML.GetVector2FromNode(n);
                }
                else if (n.name == "start_address")
                {
                    start_address = n.Value();
                }
                else if (n.name == "end_address")
                {
                    end_address = n.Value();
                }
                else if (n.name == "via_waypoint")
                {
                    via_waypoint = new ViaWaypoint(n);
                }
                else if (n.name == "arrival_time")
                {
                    arrival_time = new TextValueZone <string>(n);
                }
                else if (n.name == "departure_time")
                {
                    departure_time = new TextValueZone <string>(n);
                }
                else
                {
                    Debug.Log("Leg: " + n.name + "\n" + n.outerXml);
                }
            }

            this.steps = steps.ToArray();
        }
Exemplo n.º 2
0
        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.");
            }
        }
 public NameLocation(OnlineMapsXML node)
 {
     foreach (OnlineMapsXML n in node)
     {
         if (n.name == "location")
         {
             location = OnlineMapsXML.GetVector2FromNode(n);
         }
         else if (n.name == "name")
         {
             name = n.Value();
         }
         else
         {
             Debug.Log("NameLocation: " + n.name + "\n" + n.outerXml);
         }
     }
 }
Exemplo n.º 4
0
    /// <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(OnlineMapsXML.GetVector2FromNode(location));
        }
        catch
        {
        }
        return(Vector2.zero);
    }
 public ViaWaypoint(OnlineMapsXML node)
 {
     foreach (OnlineMapsXML n in node)
     {
         if (n.name == "location")
         {
             location = OnlineMapsXML.GetVector2FromNode(n);
         }
         else if (n.name == "step_index")
         {
             step_index = n.Value <int>();
         }
         else if (n.name == "step_interpolation")
         {
             step_interpolation = n.Value <double>();
         }
         else
         {
             Debug.Log("ViaWaypoint: " + n.name + "\n" + n.outerXml);
         }
     }
 }
 public static Vector2 GetVector2FromNode(OnlineMapsXML node)
 {
     return(OnlineMapsXML.GetVector2FromNode(node));
 }
    /// <summary>
    /// Constructor of OnlineMapsGoogleGeocodingResult.
    /// </summary>
    /// <param name="node">Location node from response</param>
    public OnlineMapsGoogleGeocodingResult(OnlineMapsXML node)
    {
        List <AddressComponent> address_components = new List <AddressComponent>();
        List <string>           types = new List <string>();
        List <string>           postcode_localities = new List <string>();

        foreach (OnlineMapsXML n in node)
        {
            if (n.name == "type")
            {
                types.Add(n.Value());
            }
            else if (n.name == "place_id")
            {
                place_id = n.Value();
            }
            else if (n.name == "formatted_address")
            {
                formatted_address = n.Value();
            }
            else if (n.name == "address_component")
            {
                address_components.Add(new AddressComponent(n));
            }
            else if (n.name == "geometry")
            {
                foreach (OnlineMapsXML gn in n)
                {
                    if (gn.name == "location")
                    {
                        geometry_location = OnlineMapsXML.GetVector2FromNode(gn);
                    }
                    else if (gn.name == "location_type")
                    {
                        geometry_location_type = gn.Value();
                    }
                    else if (gn.name == "viewport")
                    {
                        geometry_viewport_northeast = OnlineMapsXML.GetVector2FromNode(gn["northeast"]);
                        geometry_viewport_southwest = OnlineMapsXML.GetVector2FromNode(gn["southwest"]);
                    }
                    else if (gn.name == "bounds")
                    {
                        geometry_bounds_northeast = OnlineMapsXML.GetVector2FromNode(gn["northeast"]);
                        geometry_bounds_southwest = OnlineMapsXML.GetVector2FromNode(gn["southwest"]);
                    }
                    else
                    {
                        Debug.Log(n.name);
                    }
                }
            }
            else if (n.name == "partial_match")
            {
                partial_match = n.Value() == "true";
            }
            else
            {
                Debug.Log(n.name);
            }
        }

        this.address_components = address_components.ToArray();
        this.types = types.ToArray();
        this.postcode_localities = postcode_localities.ToArray();
    }
        public Step(OnlineMapsXML node)
        {
            List <Step> steps = new List <Step>();

            foreach (OnlineMapsXML n in node)
            {
                if (n.name == "travel_mode")
                {
                    travel_mode = n.Value();
                }
                else if (n.name == "start_location")
                {
                    start_location = OnlineMapsXML.GetVector2FromNode(n);
                }
                else if (n.name == "end_location")
                {
                    end_location = OnlineMapsXML.GetVector2FromNode(n);
                }
                else if (n.name == "polyline")
                {
                    polyline = OnlineMapsUtils.DecodePolylinePoints(n["points"].Value()).ToArray();
                }
                else if (n.name == "duration")
                {
                    duration = new TextValue <int>(n);
                }
                else if (n.name == "distance")
                {
                    distance = new TextValue <int>(n);
                }
                else if (n.name == "step")
                {
                    steps.Add(new Step(n));
                }
                else if (n.name == "html_instructions")
                {
                    html_instructions = n.Value();
                    if (string.IsNullOrEmpty(html_instructions))
                    {
                        return;
                    }
                    string_instructions = OnlineMapsDirectionStep.StrReplace(html_instructions,
                                                                             new[] { "&lt;", "&gt;", "&nbsp;", "&amp;", "&amp;nbsp;" },
                                                                             new[] { "<", ">", " ", "&", " " });
                    string_instructions = Regex.Replace(string_instructions, "<div.*?>", "\n");
                    string_instructions = Regex.Replace(string_instructions, "<.*?>", string.Empty);
                }
                else if (n.name == "maneuver")
                {
                    maneuver = n.Value();
                }
                else if (n.name == "transit_details")
                {
                    transit_details = new TransitDetails(n);
                }
                else
                {
                    Debug.Log("Step: " + n.name + "\n" + n.outerXml);
                }
            }

            this.steps = steps.ToArray();
        }
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="node">Place node from response</param>
    public OnlineMapsGooglePlacesResult(OnlineMapsXML node)
    {
        List <Photo>  photos       = new List <Photo>();
        List <string> types        = new List <string>();
        List <string> weekday_text = new List <string>();

        foreach (OnlineMapsXML n in node)
        {
            if (n.name == "name")
            {
                name = n.Value();
            }
            else if (n.name == "id")
            {
                id = n.Value();
            }
            else if (n.name == "vicinity")
            {
                vicinity = n.Value();
            }
            else if (n.name == "type")
            {
                types.Add(n.Value());
            }
            else if (n.name == "geometry")
            {
                location = OnlineMapsXML.GetVector2FromNode(n[0]);
            }
            else if (n.name == "rating")
            {
                rating = n.Value <float>();
            }
            else if (n.name == "icon")
            {
                icon = n.Value();
            }
            else if (n.name == "reference")
            {
                reference = n.Value();
            }
            else if (n.name == "place_id")
            {
                place_id = n.Value();
            }
            else if (n.name == "scope")
            {
                scope = n.Value();
            }
            else if (n.name == "price_level")
            {
                price_level = n.Value <int>();
            }
            else if (n.name == "formatted_address")
            {
                formatted_address = n.Value();
            }
            else if (n.name == "opening_hours")
            {
                open_now = n.Get <string>("open_now") == "true";
                foreach (OnlineMapsXML wdt in n.FindAll("weekday_text"))
                {
                    weekday_text.Add(wdt.Value());
                }
            }
            else if (n.name == "photo")
            {
                photos.Add(new Photo(n));
            }
            else
            {
                Debug.Log(n.name);
            }
        }

        this.photos       = photos.ToArray();
        this.types        = types.ToArray();
        this.weekday_text = weekday_text.ToArray();
    }