/// <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);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Try load markers from PlayerPrefs
        /// </summary>
        private void TryLoadMarkers()
        {
            // If the key does not exist, returns.
            if (!PlayerPrefs.HasKey(prefsKey))
            {
                return;
            }

            // Load xml string from PlayerPrefs
            string xmlData = PlayerPrefs.GetString(prefsKey);

            // Load xml document
            OnlineMapsXML xml = OnlineMapsXML.Load(xmlData);

            // Load markers
            foreach (OnlineMapsXML node in xml)
            {
                // Gets coordinates and label
                Vector2 position = node.Get <Vector2>("Position");
                string  label    = node.Get <string>("Label");

                // Create marker
                OnlineMaps.instance.AddMarker(position, label);
            }
        }
Exemplo n.º 3
0
    /// <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);
    }
Exemplo n.º 4
0
        /// <summary>
        /// Try load markers from PlayerPrefs
        /// </summary>
        private void TryLoadMarkers()
        {
            // If the key does not exist, returns.
            if (!PlayerPrefs.HasKey(prefsKey))
            {
                return;
            }

            // Load xml string from PlayerPrefs
            string xmlData = PlayerPrefs.GetString(prefsKey);

            // Load xml document
            OnlineMapsXML xml = OnlineMapsXML.Load(xmlData);

            // Load markers
            foreach (OnlineMapsXML node in xml)
            {
                // Gets coordinates
                Vector2 position = node.Value <Vector2>();

                // Create marker
                OnlineMapsMarker3D marker = OnlineMapsControlBase3D.instance.AddMarker3D(position, markerPrefab);
                marker.scale = markerScale;
            }
        }
Exemplo n.º 5
0
    private void GetUpdateList(string updateKey)
    {
        WebClient client = new WebClient();

        client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

        string response;

        try
        {
            response = client.UploadString("http://infinity-code.com/products_update/checkupdates.php",
                                           "k=" + WWW.EscapeURL(updateKey) + "&v=" + OnlineMaps.version + "&c=" + (int)channel);
        }
        catch (Exception exception)
        {
            Debug.Log(exception.Message);
            return;
        }

        OnlineMapsXML xml = OnlineMapsXML.Load(response);

        updates = new List <OnlineMapsUpdateItem>();

        foreach (OnlineMapsXML node in xml)
        {
            updates.Add(new OnlineMapsUpdateItem(node));
        }
    }
Exemplo n.º 6
0
    /// <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);
    }
Exemplo n.º 7
0
    /// <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);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Get data from the response Open Street Map Overpass API.
    /// </summary>
    /// <param name="response">Response from Overpass API</param>
    /// <param name="nodes">Dictionary of nodes</param>
    /// <param name="ways">List of ways</param>
    /// <param name="relations">List of relations</param>
    public static void ParseOSMResponse(string response, out Dictionary <string, OnlineMapsOSMNode> nodes, out List <OnlineMapsOSMWay> ways, out List <OnlineMapsOSMRelation> relations)
    {
        nodes     = new Dictionary <string, OnlineMapsOSMNode>(64);
        ways      = new List <OnlineMapsOSMWay>(64);
        relations = new List <OnlineMapsOSMRelation>(64);

        try
        {
            OnlineMapsXML xml = OnlineMapsXML.Load(response);

            foreach (OnlineMapsXML node in xml)
            {
                if (node.name == "node")
                {
                    OnlineMapsOSMNode osmNode = new OnlineMapsOSMNode(node);
                    nodes.Add(osmNode.id, osmNode);
                }
                else if (node.name == "way")
                {
                    ways.Add(new OnlineMapsOSMWay(node));
                }
                else if (node.name == "relation")
                {
                    relations.Add(new OnlineMapsOSMRelation(node));
                }
            }
        }
        catch
        {
            Debug.Log(response);
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Load GPX Object from string.
    /// </summary>
    /// <param name="content">A string containing GPX content.</param>
    /// <returns>Instance of GPX Object</returns>
    public static OnlineMapsGPXObject Load(string content)
    {
        OnlineMapsGPXObject instance = new OnlineMapsGPXObject();

        try
        {
            OnlineMapsXML xml = OnlineMapsXML.Load(content);

            instance.version = xml.A("version");
            instance.creator = xml.A("creator");

            foreach (OnlineMapsXML n in xml)
            {
                if (n.name == "wpt") instance.waypoints.Add(new Waypoint(n));
                else if (n.name == "rte") instance.routes.Add(new Route(n));
                else if (n.name == "trk") instance.tracks.Add(new Track(n));
                else if (n.name == "metadata") instance.metadata = new Meta(n);
                else if (n.name == "extensions") instance.extensions = n;
                else Debug.Log(n.name);
            }
        }
        catch (Exception exception)
        {
            Debug.Log(exception.Message + "\n" + exception.StackTrace);
        }

        return instance;
    }
Exemplo n.º 10
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.");
            }
        }
    /// <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 response string to a result object.
    /// </summary>
    /// <param name="response">Response string</param>
    /// <returns>Result object</returns>
    public static OnlineMapsGoogleDirectionsResult GetResult(string response)
    {
        try
        {
            OnlineMapsXML xml = OnlineMapsXML.Load(response);
            return(new OnlineMapsGoogleDirectionsResult(xml));
        }
        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);
    }
Exemplo n.º 14
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(GetVector2FromNode(location));
        }
        catch { }
        return(Vector2.zero);
    }
 /// <summary>
 /// Converts the response string to response object.
 /// </summary>
 /// <param name="response">Response string</param>
 /// <param name="outputType">Format of response string (JSON or XML)</param>
 /// <returns>Response object</returns>
 public static OnlineMapsBingMapsElevationResult GetResult(string response, Output outputType)
 {
     try
     {
         if (outputType == Output.json)
         {
             return(OnlineMapsJSON.Deserialize <OnlineMapsBingMapsElevationResult>(response));
         }
         OnlineMapsXML xml = OnlineMapsXML.Load(response);
         if (!xml.isNull)
         {
             OnlineMapsBingMapsElevationResult result = new OnlineMapsBingMapsElevationResult(xml);
             return(result);
         }
     }
     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>
    /// 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>
        /// Loading saved state.
        /// </summary>
        private void LoadState()
        {
            if (!PlayerPrefs.HasKey(key))
            {
                return;
            }

            OnlineMaps map = OnlineMaps.instance;

            OnlineMapsXML prefs = OnlineMapsXML.Load(PlayerPrefs.GetString(key));

            OnlineMapsXML generalSettings = prefs["General"];

            map.position = generalSettings.Get <Vector2>("Coordinates");
            map.zoom     = generalSettings.Get <int>("Zoom");

            List <OnlineMapsMarker> markers = new List <OnlineMapsMarker>();

            OnlineMapsMarkerManager.SetItems(markers);
        }
Exemplo n.º 20
0
        private void LoadState()
        {
            if (!PlayerPrefs.HasKey(key))
            {
                return;
            }

            OnlineMaps api = OnlineMaps.instance;

            OnlineMapsXML prefs = OnlineMapsXML.Load(PlayerPrefs.GetString(key));

            OnlineMapsXML generalSettings = prefs["General"];

            api.position = generalSettings.Get <Vector2>("Coordinates");
            api.zoom     = generalSettings.Get <int>("Zoom");

            List <OnlineMapsMarker> markers = new List <OnlineMapsMarker>();

            api.markers = markers.ToArray();
        }
Exemplo n.º 21
0
    private static void Load(OnlineMaps api)
    {
        if (!Exists())
        {
            return;
        }

        string        s    = EditorPrefs.GetString(prefsKey);
        OnlineMapsXML node = OnlineMapsXML.Load(s);

        foreach (OnlineMapsXML el in node)
        {
            string name = el.name;
            if (name == "Settings")
            {
                LoadSettings(el, api);
            }
            else if (name == "Control")
            {
                LoadControl(el, api);
            }
            else if (name == "Markers")
            {
                LoadMarkers(el, api);
            }
            else if (name == "Markers3D")
            {
                LoadMarkers3D(el, api);
            }
            else if (name == "LocationService")
            {
                LoadLocationService(el, api);
            }
        }

        EditorPrefs.DeleteKey(prefsKey);
    }
    /// <summary>
    /// Get data from the response Open Street Map Overpass API.
    /// </summary>
    /// <param name="response">Response from Overpass API</param>
    /// <param name="nodes">List of nodes</param>
    /// <param name="ways">List of ways</param>
    /// <param name="relations">List of relations</param>
    /// <param name="areas">List of areas</param>
    public static void ParseOSMResponse(string response, out List <OnlineMapsOSMNode> nodes, out List <OnlineMapsOSMWay> ways, out List <OnlineMapsOSMRelation> relations, out List <OnlineMapsOSMArea> areas)
    {
        nodes     = new List <OnlineMapsOSMNode>();
        ways      = new List <OnlineMapsOSMWay>();
        relations = new List <OnlineMapsOSMRelation>();
        areas     = new List <OnlineMapsOSMArea>();

        try
        {
            OnlineMapsXML xml = OnlineMapsXML.Load(response);

            foreach (OnlineMapsXML node in xml)
            {
                if (node.name == "node")
                {
                    nodes.Add(new OnlineMapsOSMNode(node));
                }
                else if (node.name == "way")
                {
                    ways.Add(new OnlineMapsOSMWay(node));
                }
                else if (node.name == "relation")
                {
                    relations.Add(new OnlineMapsOSMRelation(node));
                }
                else if (node.name == "area")
                {
                    areas.Add(new OnlineMapsOSMArea(node));
                }
            }
        }
        catch
        {
            Debug.Log(response);
        }
    }