Beispiel #1
0
    /// <summary>
    /// Creates a new request for a location search.\n
    /// This method is used for Reverse Geocoding.\n
    /// https://developers.google.com/maps/documentation/geocoding/intro#Geocoding
    /// </summary>
    /// <param name="address">Location title</param>
    /// <param name="latlng">Location coordinates (latitude,longitude). Example: 40.714224,-73.961452.</param>
    /// <param name="lang">Language of result</param>
    /// <returns>Instance of the search query.</returns>
    public static OnlineMapsGoogleAPIQuery Find(string address = null, string latlng = null, string lang = null)
    {
        OnlineMapsFindLocation query = new OnlineMapsFindLocation(address, latlng, lang);

        OnlineMaps.instance.AddGoogleAPIQuery(query);
        return(query);
    }
Beispiel #2
0
        private void OnFindLocationComplete(string result)
        {
            Vector2 position = OnlineMapsFindLocation.GetCoordinatesFromResult(result);

            if (position == Vector2.zero)
            {
                return;
            }

            if (searchMarker == null)
            {
                searchMarker = api.AddMarker(position, search);
            }
            else
            {
                searchMarker.position = position;
                searchMarker.label    = search;
            }

            if (api.zoom < 13)
            {
                api.zoom = 13;
            }

            api.position = position;
            api.Redraw();
        }
Beispiel #3
0
    /// <summary>
    /// Creates a new request for a location search.\n
    /// This method is used for Reverse Geocoding.\n
    /// https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
    /// </summary>
    /// <param name="lnglat">Location coordinates</param>
    /// <param name="lang">Language of result</param>
    /// <returns>Instance of the search query.</returns>
    public static OnlineMapsGoogleAPIQuery Find(Vector2 lnglat, string lang = null)
    {
        OnlineMapsFindLocation query = new OnlineMapsFindLocation(null, string.Format("{0},{1}", lnglat.y, lnglat.x), lang);

        OnlineMaps.instance.AddGoogleAPIQuery(query);
        return(query);
    }
Beispiel #4
0
        private void OnFindLocationComlete(string result)
        {
            Debug.Log("complete home location search " + result);
            //OnlineMapsMarker marker = OnlineMapsFindLocationResult
            Vector2 position = OnlineMapsFindLocation.GetCoordinatesFromResult(result);

            Debug.Log(position);

            if (position == Vector2.zero)
            {
                return;
            }

            if (searchMarker == null)
            {
                Debug.Log("OK");
                searchMarker = OnlineMaps.instance.AddMarker(position, "XAD");
            }
            else
            {
                searchMarker.position = position;
                searchMarker.label    = "XAD";
            }

            //if (api.zoom < 13) api.zoom = 13;

            OnlineMaps.instance.position = position;
            OnlineMaps.instance.Redraw();
        }
        private void Start()
        {
            // Start search Chicago.
            OnlineMapsGoogleAPIQuery query = OnlineMapsFindLocation.Find("Chicago");

            // Specifies that search results should be sent to OnFindLocationComplete.
            query.OnComplete += OnFindLocationComplete;
        }
        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 = OnlineMapsFindLocation.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 = OnlineMapsFindLocation.GetVector2FromNode(southwest);
                        Vector2 ne = OnlineMapsFindLocation.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.");
            }
        }
Beispiel #7
0
        private void OnMapClick()
        {
            // Get the coordinates where the user clicked.
            Vector2 mouseCoords = OnlineMapsControlBase.instance.GetCoords();

            // Try find location name by coordinates.
            OnlineMapsGoogleAPIQuery query = OnlineMapsFindLocation.Find(null, mouseCoords.y + "," + mouseCoords.x);

            query.OnComplete += OnQueryComplete;
        }
Beispiel #8
0
        private void Start()
        {
            // Gets Location Service Component.
//			OnlineMapsLocationService ls = OnlineMapsLocationService.instance;
//
//			if (ls == null)
//			{
//				Debug.LogError(
//					"Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service).");
//				return;
//			}
//
//
//			ls.OnCompassChanged += OnCompassChanged;
            Debug.Log("find address " + homeAddress);
            OnlineMapsFindLocation.Find(homeAddress).OnComplete += OnFindLocationComlete;

            // Looking for a route between locations.
            // OnlineMapsFindDirection.Find(fromPlace, toPlace).OnComplete += OnComplete;
        }
Beispiel #9
0
 private void FindLocation()
 {
     OnlineMapsFindLocation.Find(search).OnComplete += delegate(string s)
     {
         try
         {
             Vector2 position = OnlineMapsFindLocation.GetCoordinatesFromResult(s);
             if (position != Vector2.zero)
             {
                 OnlineMaps.instance.position = position;
             }
             else
             {
                 Debug.Log(s);
             }
         }
         catch
         {
             Debug.Log(s);
         }
     };
 }
Beispiel #10
0
 public OnlineMapsGoogleAPIQuery FindLocation(string search)
 {
     OnlineMapsFindLocation fl = new OnlineMapsFindLocation(search);
     fl.OnComplete += OnlineMapsFindLocation.MovePositionToResult;
     googleQueries.Add(fl);
     return fl;
 }
Beispiel #11
0
 public OnlineMapsFindLocation FindLocation(string search, Action<string> callback)
 {
     OnlineMapsFindLocation fl = new OnlineMapsFindLocation(search);
     fl.OnComplete += callback;
     googleQueries.Add(fl);
     return fl;
 }
Beispiel #12
0
        private void OnGUI()
        {
            if (api == null)
            {
                api = OnlineMaps.instance;
            }
            int labelFontSize     = GUI.skin.label.fontSize;
            int buttonFontSize    = GUI.skin.button.fontSize;
            int toggleFontSize    = GUI.skin.toggle.fontSize;
            int textFieldFontSize = GUI.skin.textField.fontSize;

            GUI.skin.label.fontSize       = 20;
            GUI.skin.button.fontSize      = 20;
            GUI.skin.toggle.fontSize      = 20;
            GUI.skin.toggle.contentOffset = new Vector2(5, -5);
            GUI.skin.textField.fontSize   = 20;

            if (GUI.Button(new Rect(5, 5, 50, 50), is2D ? "3D" : "2D") && !isCameraModeChange)
            {
                ChangeMode();
            }

            if (rowStyle == null)
            {
                rowStyle = new GUIStyle(GUI.skin.button);
                RectOffset margin = rowStyle.margin;
                rowStyle.margin = new RectOffset(margin.left, margin.right, 1, 1);
            }

            if (activeRowStyle == null)
            {
                activeRowStyle = new GUIStyle(GUI.skin.button);
                activeRowStyle.normal.background = activeRowStyle.hover.background;
                RectOffset margin = activeRowStyle.margin;
                activeRowStyle.margin = new RectOffset(margin.left, margin.right, 1, 1);
            }

            if (GUI.Button(new Rect(5, 60, 50, 50), "+"))
            {
                api.zoom++;
            }

            Color defBackgroundColor = GUI.backgroundColor;

            for (int i = 20; i > 2; i--)
            {
                if (api.zoom == i)
                {
                    GUI.backgroundColor = Color.green;
                }
                if (GUI.Button(new Rect(5, 115 + (20 - i) * 15, 50, 10), ""))
                {
                    api.zoom = i;
                }
                GUI.backgroundColor = defBackgroundColor;
            }

            if (GUI.Button(new Rect(5, 390, 50, 50), "-"))
            {
                api.zoom--;
            }

            GUI.Box(new Rect(65, 5, Screen.width - 70, 75), "");

            GUI.Label(new Rect(75, 10, 150, 50), "Find place:");
            search = GUI.TextField(new Rect(200, 10, Screen.width - 320, 30), search);
            if (Event.current.type == EventType.KeyUp && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
            {
                OnlineMapsFindLocation.Find(search).OnComplete += OnFindLocationComplete;
            }
            if (GUI.Button(new Rect(Screen.width - 110, 10, 100, 30), "Search"))
            {
                OnlineMapsFindLocation.Find(search).OnComplete += OnFindLocationComplete;
            }

            GUI.Label(new Rect(75, 45, 100, 30), "Show:");

            api.labels           = GUI.Toggle(new Rect(200, 50, 100, 30), api.labels, "Labels");
            api.traffic          = GUI.Toggle(new Rect(300, 50, 100, 30), api.traffic, "Traffic");
            control.useElevation = !is2D && GUI.Toggle(new Rect(400, 50, 110, 30), control.useElevation, "Elevation");

            GUI.skin.label.fontSize       = labelFontSize;
            GUI.skin.button.fontSize      = buttonFontSize;
            GUI.skin.toggle.fontSize      = toggleFontSize;
            GUI.skin.toggle.contentOffset = Vector2.zero;
            GUI.skin.textField.fontSize   = textFieldFontSize;
        }
 /// <summary>
 /// Creates a new request for a location search.\n
 /// This method is used for Reverse Geocoding.\n
 /// https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
 /// </summary>
 /// <param name="latlng">Location coordinates</param>
 /// <returns>Instance of the search query.</returns>
 public static OnlineMapsGoogleAPIQuery Find(Vector2 latlng)
 {
     OnlineMapsFindLocation query = new OnlineMapsFindLocation(null, string.Format("{0},{1}", latlng.y, latlng.x));
     OnlineMaps.instance.AddGoogleAPIQuery(query);
     return query;
 }
 /// <summary>
 /// Creates a new request for a location search.\n
 /// This method is used for Reverse Geocoding.\n
 /// https://developers.google.com/maps/documentation/geocoding/intro#Geocoding
 /// </summary>
 /// <param name="address">Location title</param>
 /// <param name="latlng">Location coordinates</param>
 /// <returns>Instance of the search query.</returns>
 public static OnlineMapsGoogleAPIQuery Find(string address = null, string latlng = null)
 {
     OnlineMapsFindLocation query = new OnlineMapsFindLocation(address, latlng);
     OnlineMaps.instance.AddGoogleAPIQuery(query);
     return query;
 }