/// <summary>
        /// Moves the camera and refreshes the map as the player moves.
        /// </summary>
        private void Update()
        {
            if (MapsService == null)
            {
                return;
            }

            // Get the current map location.
            LatLng currentLocation =
                new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);
            Vector3 currentWorldLocation = MapsService.Coords.FromLatLngToVector3(currentLocation);

            // Move the camera to the current map location.
            Vector3 targetCameraPosition = new Vector3(currentWorldLocation.x,
                                                       Camera.main.transform.position.y, currentWorldLocation.z);

            Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,
                                                          targetCameraPosition, Time.deltaTime * 5);

            // Only move the map location if the device has moved more than 2 meters.
            if (Vector3.Distance(Vector3.zero, currentWorldLocation) > 2)
            {
                MapsService.MoveFloatingOrigin(currentLocation, new[] { Camera.main.gameObject });
                MapsService.LoadMap(ExampleDefaults.DefaultBounds,
                                    ExampleDefaults.DefaultGameObjectOptions);
                PreviousLocation = currentLocation;
            }
        }
Ejemplo n.º 2
0
    void ObjectTrackUserLocation()
    {
        currentLocation = new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);
        Vector3 currentposition = mapsService.Coords.FromLatLngToVector3(currentLocation);
        Vector3 targetPosition  = new Vector3(currentposition.x, MyLocationMaker.transform.position.y, currentposition.z);

        MyLocationMaker.transform.position =
            Vector3.Lerp(MyLocationMaker.transform.position, targetPosition, Time.deltaTime * 5);


        // Only move the map location if the device has moved more than 2 meters.
        if (Vector3.Distance(Vector3.zero, currentposition) > 500f)
        {
            mapsService.MoveFloatingOrigin(currentLocation, new[] { MyLocationMaker.gameObject });
            LoadMap();
            PreviousLocation = currentLocation;
        }
    }
Ejemplo n.º 3
0
        public void Recenter(Vector3 newCenter)
        {
            // Update map origin and get the offset due to the previous one
            var originOffset = _mapsService.MoveFloatingOrigin(newCenter, _objectsToRecenter);

            // Notify listeners
            onMapOriginUpdate.Invoke(originOffset);
            // Remember the new origin point
            _floatingOrigin = newCenter;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Triggered when a valid location info is returned from the Unity Input locations service.
        /// </summary>
        /// <param name="locationInfo">Location Info</param>
        private void OnLocationServicesEvalComplete(LocationInfo locationInfo)
        {
            if (HasGPSLocation) // aka we were able to get a valid GPS location
            {
                LatLng = new LatLng(locationInfo.latitude, locationInfo.longitude);
                MapsService.MoveFloatingOrigin(LatLng);
                Avatar.transform.position = MapsService.Coords.FromLatLngToVector3(LatLng);
            }

            base.LoadMap();
        }
Ejemplo n.º 5
0
        public void SetCenter(double latitude, double longitude)
        {
            var latlng = new LatLng(latitude, longitude);

            mapsService.MoveFloatingOrigin(latlng, movedObjects);
            _signalBus.Fire <MapOriginChanged>();

            var coords = mapsService.Coords.FromLatLngToVector3(latlng);

            cameraControl.SetPosition(coords);
            mapsUpdater.LoadMap();
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Follow player's real-world location, as derived from the device's GPS signal.
    /// </summary>
    private IEnumerator Follow()
    {
        // If location is allowed by the user, start the location service and compass, otherwise abort
        // the coroutine.
        if (Input.location.isEnabledByUser)
        {
            Input.location.Start();
            Input.compass.enabled = true;
        }
        else
        {
            Debug.LogError("Location Services not enabled by the user.");
            yield break;
        }

        // Wait for the location service to start.
        while (true)
        {
            if (Input.location.status == LocationServiceStatus.Initializing)
            {
                // Starting, just wait.
                yield return(new WaitForSeconds(1f));
            }
            else if (Input.location.status == LocationServiceStatus.Failed)
            {
                // Failed, abort the coroutine.
                Debug.LogError("Location Services failed to start.");
                yield break;
            }
            else if (Input.location.status == LocationServiceStatus.Running)
            {
                // Started, continue the coroutine.
                break;
            }
        }

        // Get the MapsService component and load it at the device location.
        LatLng previousLocation = new LatLng(
            Input.location.lastData.latitude, Input.location.lastData.longitude);
        MapsService mapsService = GetComponent <MapsService>();

        mapsService.InitFloatingOrigin(previousLocation);
        mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);

        // Every second, move the map location to the device location.
        while (true)
        {
            yield return(new WaitForSeconds(1f));

            // Only move the map location if the device has moved more than 2 meters.
            LatLng currentLocation = new LatLng(
                Input.location.lastData.latitude, Input.location.lastData.longitude);
            float distance = Vector3.Distance(
                Vector3.zero, mapsService.Coords.FromLatLngToVector3(currentLocation));
            if (distance > 2)
            {
                mapsService.MoveFloatingOrigin(currentLocation);
                previousLocation = currentLocation;
            }
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Follow player's real-world location, as derived from the device's GPS signal.
        /// </summary>
        private IEnumerator Follow()
        {
            // If location is allowed by the user, start the location service and compass, otherwise abort
            // the coroutine.
      #if PLATFORM_IOS
            // The location permissions request in IOS does not seem to get invoked until it is called for
            // in the code. It happens at runtime so if the code is not trying to access the location
            // right away, it will not pop up the permissions dialog.
            Input.location.Start();
      #endif

            while (!Input.location.isEnabledByUser)
            {
                Debug.Log("Waiting for location services to become enabled..");
                yield return(new WaitForSeconds(1f));
            }
            Debug.Log("Location services is enabled.");

      #if !PLATFORM_IOS
            Input.location.Start();
      #endif

            Input.compass.enabled = true;

            // Wait for the location service to start.
            while (true)
            {
                if (Input.location.status == LocationServiceStatus.Initializing)
                {
                    // Starting, just wait.
                    yield return(new WaitForSeconds(1f));
                }
                else if (Input.location.status == LocationServiceStatus.Failed)
                {
                    // Failed, abort the coroutine.
                    Debug.LogError("Location Services failed to start.");

                    yield break;
                }
                else if (Input.location.status == LocationServiceStatus.Running)
                {
                    // Started, continue the coroutine.
                    break;
                }
            }

            // Get the MapsService component and load it at the device location.
            LatLng previousLocation =
                new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);
            MapsService mapsService = GetComponent <MapsService>();
            mapsService.InitFloatingOrigin(previousLocation);
            mapsService.LoadMap(ExampleDefaults.DefaultBounds, ExampleDefaults.DefaultGameObjectOptions);

            // Every second, move the map location to the device location.
            while (true)
            {
                yield return(new WaitForSeconds(1f));

                // Only move the map location if the device has moved more than 2 meters.
                LatLng currentLocation =
                    new LatLng(Input.location.lastData.latitude, Input.location.lastData.longitude);

                float distance =
                    Vector3.Distance(Vector3.zero, mapsService.Coords.FromLatLngToVector3(currentLocation));

                if (distance > 2)
                {
                    mapsService.MoveFloatingOrigin(currentLocation);
                    previousLocation = currentLocation;
                }
            }
        }