Example #1
0
        /// <summary>
        /// Convert Vector3 World Space location to Position taking account of zoom, scale and mapscale
        /// </summary>
        /// <param name="position">Vector3 World Space coordinates</param>
        /// <returns>Position</returns>
        static public IPosition ToPosition(this Vector3 position)
        {
            Vector3 mapLocal = AppState.instance.map.transform.InverseTransformPoint(position);

            Mapbox.Utils.Vector2d _latlng = VectorExtensions.GetGeoPosition(mapLocal, AppState.instance.abstractMap.CenterMercator, AppState.instance.abstractMap.WorldRelativeScale);
            return(new Position(_latlng.x, _latlng.y, mapLocal.y));
        }
Example #2
0
        public void UpdateSpotList(Mapbox.Utils.Vector2d vec)
        {
            var spots      = MapSceneManager.Data.spotList;
            var removeList = new List <Result>();

            foreach (var s in spots)
            {
                var distance = ConvertDistance.Distance(vec.x, vec.y, s.geometry.location.lat, s.geometry.location.lng, 'K');
                if (distance > 6)
                {
                    removeList.Add(s);
                }
                if (distance <= 3)
                {
                    MapSceneManager.Boad.InstantiateBoad(s);
                }
                if (distance > 3)
                {
                    MapSceneManager.Boad.DestroyBoad(s);
                }
            }

            //最後にリストから消去
            foreach (var r in removeList)
            {
                spots.Remove(r);
            }
        }
Example #3
0
        // Update is called once per frame
        public void PlayerTransUpdate()
        {
            velocity = Vector3.zero;

            var map      = MapSceneManager.MainMap;
            var location = new Mapbox.Utils.Vector2d(locationGetter.Latitude, locationGetter.Longitude);
            var pos      = map.GeoToWorldPosition(location) + offset;

            velocity    = pos;
            oldVelocity = transform.localPosition;

            if (Vector3.Distance(transform.position, pos) > 0.05f)
            {
                var moveDirection = (pos - transform.position).normalized;
                velocity = new Vector3(moveDirection.x * moveSpeed, transform.position.y, moveDirection.z * moveSpeed);

                transform.LookAt(transform.position + new Vector3(moveDirection.x, 0, moveDirection.z));
                OnRunMotion();
            }
            else
            {
                velocity = Vector3.zero;
                OffRunMotion();
            }


            transform.localPosition += velocity * Time.deltaTime;
            //cCon.Move(velocity * Time.deltaTime);

            //transform.localPosition = pos;

            string positionTextTemplate = "x: {0}\ny: {1}";

            MapSceneManager.UI.SetPositionText(string.Format(positionTextTemplate, transform.position.x, transform.position.y));
        }
Example #4
0
 void LocationProvider_OnLocationUpdated(Location location)
 {
     if (_isInitialized && location.IsLocationUpdated)
     {
         latlon          = location.LatitudeLongitude;
         _targetPosition = _map.GeoToWorldPosition(location.LatitudeLongitude);
     }
 }
 void LocationProvider_OnLocationUpdated(Location location)
 {
     if (_isInitialized)
     {
         latlon          = location.LatitudeLongitude;
         _targetPosition = Conversions.GeoToWorldPosition(location.LatitudeLongitude,
                                                          _map.CenterMercator,
                                                          _map.WorldRelativeScale).ToVector3xz();
     }
 }
Example #6
0
        /// <summary>
        /// 更新処理
        /// </summary>
        void Update()
        {
            _upDateData++;

            if (_upDateData < 60)
            {
                Mapbox.Utils.Vector2d _lotAndLong = Mapbox.Unity.Utilities.Conversions.StringToLatLon(_getNowLotAndLong.Latitude.ToString() + "," + _getNowLotAndLong.Longitude.ToString());
                //_abstractMap.SetCenterLatitudeLongitude(_lotAndLong);
                _abstractMap.UpdateMap(_lotAndLong, 14);
            }

            _upDateData = _upDateData < 60 ? 0 : _upDateData;
        }
Example #7
0
        IEnumerator LoadMapData(Mapbox.Utils.Vector2d vec)
        {
            var trans = vec.x.ToString() + "," + vec.y;

            UriBuilder builder = new UriBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json");

            builder.Query += "radius=6000";
            //builder.Query += "&key=" + token;
            builder.Query += "&location=" + trans;
            builder.Query += "&type=restaurant";
            var uri = builder.Uri;

            Debug.Log(uri);

            using (UnityWebRequest www = UnityWebRequest.Get(uri))
            {
                var sendRequest = www.SendWebRequest();
                while (!sendRequest.isDone)
                {
                    yield return(null);
                }

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    // Show results as text
                    //Debug.Log(www.downloadHandler.text);

                    var resultsString = www.downloadHandler.text;

                    var data = JsonUtility.FromJson <Response>(resultsString);
                    foreach (var d in data.results)
                    {
                        if (!MapSceneManager.Data.spotList.Contains(d))
                        {
                            MapSceneManager.Data.spotList.Add(d);
                        }
                    }

                    //spotlistに更新をかける(現在地より6km以上離れた要素は削除する)
                    UpdateSpotList(vec);
                }
            }
        }
Example #8
0
        // Use this for initialization
        public void Setup()
        {
            Mapbox.Utils.Vector2d location;
            if (locationGetter.CanGetLonLat())
            {
                Debug.Log("マップ生成");
                location = new Mapbox.Utils.Vector2d(locationGetter.Latitude, locationGetter.Longitude);
            }
            else
            {
                location = new Mapbox.Utils.Vector2d(35.7134029f, 139.7611094);
            }

            maps.Initialize(location, 15);
            maps.UpdateMap(location);

            //Mapbox.Utils.Vector2d location = new Mapbox.Utils.Vector2d(locationGetter.Latitude, locationGetter.Longitude);

            offset = transform.localPosition;
        }
Example #9
0
        protected override void OnUpdate()
        {
            if (MapSceneManager.IsDebug)
            {
                var data     = MapSceneManager.Data;
                var location = MapSceneManager.MainMap.WorldToGeoPosition(MapSceneManager.Player.gameObject.transform.position);
                if (ConvertDistance.Distance(location.x, location.y, data.beforeLat, data.beforeLng, 'K') >= 3)
                {
                    data.beforeLat = location.x;
                    data.beforeLng = location.y;
                    enumerator     = LoadMapData(location);
                }
            }
            if (MapSceneManager.Getter.CanGetLonLat())
            {
                string lonLatInfoTemplate = "緯度: {0}\n経度: {1}";
                MapSceneManager.UI.SetText(string.Format(lonLatInfoTemplate, (float)MapSceneManager.Getter.Latitude, (float)MapSceneManager.Getter.Longitude));
                MapSceneManager.Player.PlayerTransUpdate();

                var getter = MapSceneManager.Getter;
                var data   = MapSceneManager.Data;
                //前に更新した時より3km以上離れていたら更新する
                if (ConvertDistance.Distance(getter.Latitude, getter.Longitude, data.beforeLat, data.beforeLng, 'K') >= 3)
                {
                    data.beforeLat = getter.Latitude;
                    data.beforeLng = getter.Longitude;
                    var vec = new Mapbox.Utils.Vector2d(getter.Latitude, getter.Longitude);
                    enumerator = LoadMapData(vec);
                }
            }

            if (enumerator != null)
            {
                if (!enumerator.MoveNext())
                {
                    enumerator = null;
                }
            }
        }
Example #10
0
        public void PlacePokemon(Mapbox.Utils.Vector2d initialLocation)
        {
            //loop through all pokemon instantiate at location
            foreach (GameObject pokemon in pokemonMapObjects)
            {
                //float randomLat = UnityEngine.Random.Range (-.0002f, .0002f);
                //float randomLong = UnityEngine.Random.Range (-.0002f, .0002f);

                float randomLat  = UnityEngine.Random.Range(-.001f, .001f);
                float randomLong = UnityEngine.Random.Range(-.001f, .001f);

                //create new random location close to users initial location
                Mapbox.Utils.Vector2d pokemonLocation = new Mapbox.Utils.Vector2d(initialLocation.x + randomLat, initialLocation.y + randomLong);

                /*test to see if real world distance matches unity distance...It does not unfortunately. Tested with an online distance
                 * calculator and it was off by a different factor each time. To get accurate distances in AR scene it could be possible by placing
                 * objects based on gps distance relative to player assuming one unity scene unit to be one meter.
                 * if (pokemon.name.Contains ("mewtwo")) {
                 *      print (pokemon.name + ": " + pokemonLocation);
                 *      GameObject player = GameObject.Find ("Player");
                 *      print("Unity Distance: " + Vector3.Distance(pokemon.transform.position,player.transform.position));
                 * }
                 */

                //calculate map location
                Vector3 _targetPosition = Conversions.GeoToWorldPosition(pokemonLocation,
                                                                         _map.CenterMercator,
                                                                         _map.WorldRelativeScale).ToVector3xz();

                GameObject currentPokemon = Instantiate(pokemon);
                //position POI on map
                currentPokemon.transform.position = _targetPosition;
                currentPokemon.transform.position = _targetPosition;
                //get name so we can write to dictionary
                string currentPokemonName = currentPokemon.name.Substring(0, currentPokemon.name.Length - 10);
                //add pokemon map object to poke object manager that holds all transforms and persists between scenes so we can attempt to accuratly place pokemon and gyms in AR scene.
                PokeObjectManager.Instance.pokeObjects.Add(currentPokemonName, currentPokemon.transform);
            }
        }
Example #11
0
        public void InstantiateBoad(Result result)
        {
            if (!generatedList.ContainsKey(result))
            {
                double latitude  = result.geometry.location.lat;
                double longitude = result.geometry.location.lng;

                var map = MapSceneManager.MainMap;

                var location      = new Mapbox.Utils.Vector2d(latitude, longitude);
                var localPotision = map.GeoToWorldPosition(location) + boadPrefab.transform.position;

                bool allActive = true;
                foreach (var obj in poolObj)
                {
                    if (!obj.active)
                    {
                        generatedList.Add(result, obj);
                        obj.transform.position = localPotision;
                        var boadSet = obj.GetComponent <BoadSet>();
                        boadSet.SetUp(result.place_id, result.name, result.icon);
                        obj.SetActive(true);
                        activeCount++;
                        allActive = false;
                        break;
                    }
                }
                if (allActive)
                {
                    var obj = Instantiate(boadPrefab, localPotision, boadPrefab.transform.rotation, this.transform);
                    generatedList.Add(result, obj);
                    poolObj.Add(obj);
                    activeCount++;

                    var boadSet = obj.GetComponent <BoadSet>();
                    boadSet.SetUp(result.place_id, result.name, result.icon);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Initializes the map using the mapOptions.
        /// </summary>
        /// <param name="options">Options.</param>
        protected virtual void InitializeMap(MapOptions options)
        {
            Options           = options;
            _worldHeightFixed = false;
            _fileSource       = MapboxAccess.Instance;
            //
            //add loca m
            //
            float p_lat = PlayerPrefs.GetFloat("_lat_c"), p_long = PlayerPrefs.GetFloat("_long_c");

            Mapbox.Utils.Vector2d tp_locations = new Mapbox.Utils.Vector2d(p_lat, p_long);
            Debug.Log("set cord: " + tp_locations);
            //
            //_centerLatitudeLongitude = Conversions.StringToLatLon(options.locationOptions.latitudeLongitude);

            _centerLatitudeLongitude = tp_locations;

            //

            _initialZoom = (int)options.locationOptions.zoom;

            options.scalingOptions.scalingStrategy.SetUpScaling(this);
            options.placementOptions.placementStrategy.SetUpPlacement(this);


            //Set up events for changes.
            _imagery.UpdateLayer += OnImageOrTerrainUpdateLayer;
            _terrain.UpdateLayer += OnImageOrTerrainUpdateLayer;

            _vectorData.SubLayerRemoved += OnVectorDataSubLayerRemoved;
            _vectorData.SubLayerAdded   += OnVectorDataSubLayerAdded;
            _vectorData.UpdateLayer     += OnVectorDataUpdateLayer;

            _options.locationOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) =>
            {
                UpdateMap();
            };

            _options.extentOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) =>
            {
                OnTileProviderChanged();
            };

            _options.extentOptions.defaultExtents.PropertyHasChanged += (object sender, System.EventArgs eventArgs) =>
            {
                if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false)
                {
                    Debug.Log("defaultExtents");
                    return;
                }
                if (TileProvider != null)
                {
                    TileProvider.UpdateTileExtent();
                }
            };

            _options.placementOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) =>
            {
                SetPlacementStrategy();
                UpdateMap();
            };

            _options.scalingOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) =>
            {
                SetScalingStrategy();
                UpdateMap();
            };

            _mapVisualizer.Initialize(this, _fileSource);
            TileProvider.Initialize(this);

            SendInitialized();

            TileProvider.UpdateTileExtent();
        }