Esempio n. 1
0
        private void OnComplete(string s)
        {
            OnlineMapsFindPlacesResult[] results = OnlineMapsFindPlaces.GetResults(s);
            if (results == null)
            {
                Debug.Log("Error");
                Debug.Log(s);
                return;
            }

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

            foreach (OnlineMapsFindPlacesResult result in results)
            {
                Debug.Log(result.name);
                Debug.Log(result.location);

                OnlineMapsMarker marker = OnlineMaps.instance.AddMarker(result.location, result.name);
                markers.Add(marker);
            }

            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(markers.ToArray(), out center, out zoom);

            OnlineMaps.instance.position = center;
            OnlineMaps.instance.zoom     = zoom + 1;
        }
        private void OnGeocodingComplete(string response)
        {
            OnlineMapsGoogleGeocodingResult[] results = OnlineMapsGoogleGeocoding.GetResults(response);
            if (results == null || results.Length == 0)
            {
                Debug.Log(response);
                return;
            }

            OnlineMapsGoogleGeocodingResult r = results[0];

            OnlineMaps.instance.position = r.geometry_location;

            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(new[] { r.geometry_bounds_northeast, r.geometry_bounds_southwest }, out center, out zoom);
            OnlineMaps.instance.zoom = zoom;

            if (marker == null)
            {
                marker = OnlineMapsMarkerManager.CreateItem(r.geometry_location, r.formatted_address);
            }
            else
            {
                marker.position = r.geometry_location;
                marker.label    = r.formatted_address;
            }
        }
        private void Start()
        {
            OnlineMaps map = OnlineMaps.instance;

            // Create markers.
            OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0));
            OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0.01f));
            OnlineMapsMarkerManager.CreateItem(new Vector2(0, -0.01f));

            // Sets a new comparer.
            OnlineMapsMarkerFlatDrawer drawer = (OnlineMapsTileSetControl.instance.markerDrawer as OnlineMapsMarkerFlatDrawer);

            if (drawer != null)
            {
                drawer.markerComparer = new MarkerComparer();
            }

            // Get the center point and zoom the best for all markers.
            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(OnlineMapsMarkerManager.instance.ToArray(), out center, out zoom);

            // Change the position and zoom of the map.
            map.position = center;
            map.zoom     = zoom;
        }
Esempio n. 4
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.");
            }
        }
        private void OnGUI()
        {
            if (GUI.Button(new Rect(5, 5, 100, 20), "Center"))
            {
                Vector2 center;
                int     zoom;

                // Get the center point and zoom the best for all markers.
                OnlineMapsUtils.GetCenterPointAndZoom(OnlineMaps.instance.markers, out center, out zoom);

                // Change the position and zoom of the map.
                OnlineMaps.instance.position = center;
                OnlineMaps.instance.zoom     = zoom;
            }
        }
        private void Start()
        {
            OnlineMaps api = OnlineMaps.instance;

            mapMarkerMiddle = api.AddMarker(new Vector2(0, 0));
            mapMarkerTop    = api.AddMarker(new Vector2(0, 0.01f));
            mapMarkerBottom = api.AddMarker(new Vector2(0, -0.01f));

            OnlineMapsTileSetControl.instance.markerComparer = new MarkerComparer();

            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(api.markers, out center, out zoom);

            api.position = center;
            api.zoom     = zoom;
        }
Esempio n. 7
0
    public void CenterMapOnData()
    {
        Vector2 center;
        int     zoom;

        var listOfMarkers = mapPoints.Select(t => (t as MapPointMarker)?.getMarker2D() as OnlineMapsMarkerBase);

        //Debug.LogFormat("OnlineMapsMarkerManager count : {0}",OnlineMapsMarkerManager.instance.items.Count);
        // Get the center point and zoom the best for all markers.
        OnlineMapsUtils.GetCenterPointAndZoom(OnlineMapsMarkerManager.instance.ToArray(), out center, out zoom);

        //Debug.LogFormat("Zoom Level: {0}",zoom);
        //Debug.LogFormat("Center: {0} ; {1}",center.x,center.y);
        // Change the position and zoom of the map.


        map.fixZoomInterval(OnlineMaps.instance, 2, Mathf.Max(zoom, 14));
        map.setViewerZoom(zoom);
        //map.setViewerPosition(center.x, center.y);
    }
        private void Start()
        {
            OnlineMaps api = OnlineMaps.instance;

            // Create markers.
            api.AddMarker(new Vector2(0, 0));
            api.AddMarker(new Vector2(0, 0.01f));
            api.AddMarker(new Vector2(0, -0.01f));

            // Sets a new comparer.
            OnlineMapsTileSetControl.instance.markerComparer = new MarkerComparer();

            // Get the center point and zoom the best for all markers.
            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(api.markers, out center, out zoom);

            // Change the position and zoom of the map.
            api.position = center;
            api.zoom     = zoom;
        }
Esempio n. 9
0
    private void OnGeocodeComplete(OnlineMapsWWW www)
    {
        if (www.hasError)
        {
            Debug.Log(www.error);
            return;
        }

        OnlineMapsJSONItem json      = OnlineMapsJSON.Parse(www.text);
        OnlineMapsJSONItem firstItem = json["candidates/0"];

        if (firstItem == null)
        {
            return;
        }

        OnlineMapsVector2d center = firstItem["location"].Deserialize <OnlineMapsVector2d>();

        OnlineMapsJSONItem extent = firstItem["extent"];
        double             xmin   = extent.V <double>("xmin"),
                           ymin = extent.V <double>("ymin"),
                           xmax = extent.V <double>("xmax"),
                           ymax = extent.V <double>("ymax");

        Vector2[] points =
        {
            new Vector2((float)xmin, (float)ymin),
            new Vector2((float)xmax, (float)ymax),
        };

        Vector2 c;
        int     zoom;

        OnlineMapsUtils.GetCenterPointAndZoom(points, out c, out zoom);

        OnlineMaps.instance.SetPositionAndZoom(center.x, center.y, zoom);
    }
Esempio n. 10
0
        /// <summary>
        /// This method is called when a response is received.
        /// </summary>
        /// <param name="s">Response string</param>
        private void OnComplete(string s)
        {
            // Trying to get an array of results.
            OnlineMapsGooglePlacesResult[] results = OnlineMapsGooglePlaces.GetResults(s);

            // If there is no result
            if (results == null)
            {
                Debug.Log("Error");
                Debug.Log(s);
                return;
            }

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

            foreach (OnlineMapsGooglePlacesResult result in results)
            {
                // Log name and location of each result.
                Debug.Log(result.name);
                Debug.Log(result.location);

                // Create a marker at the location of the result.
                OnlineMapsMarker marker = OnlineMaps.instance.AddMarker(result.location, result.name);
                markers.Add(marker);
            }

            // Get center point and best zoom for markers
            Vector2 center;
            int     zoom;

            OnlineMapsUtils.GetCenterPointAndZoom(markers.ToArray(), out center, out zoom);

            // Set map position and zoom.
            OnlineMaps.instance.position = center;
            OnlineMaps.instance.zoom     = zoom + 1;
        }