/// <summary>
        /// Called to begin the linear interpolation
        /// </summary>
        private void StartLerping(Unity.Location.Location location)
        {
            _isLerping          = true;
            _timeStartedLerping = Time.time;
            timeTakenDuringLerp = Time.deltaTime;

            //We set the start position to the current position
            _startLatLong  = _map.CenterLatitudeLongitude;
            _endLatlong    = location.LatitudeLongitude;
            _startPosition = _map.GeoToWorldPosition(_startLatLong, false);
            _endPosition   = _map.GeoToWorldPosition(_endLatlong, false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a vector feature from lat lon and builds that feature using the modifier stack.
        /// </summary>
        /// <param name="layer">Layer.</param>
        /// <param name="tile">Tile.</param>
        private void BuildFeatureFromLatLon(VectorTileLayer layer, UnityTile tile)
        {
            if (tile.TileState != Enums.TilePropertyState.Unregistered)
            {
                string[] coordinates = (SubLayerProperties as PrefabItemOptions).coordinates;

                for (int i = 0; i < coordinates.Length; i++)
                {
                    if (string.IsNullOrEmpty(coordinates[i]))
                    {
                        return;
                    }

                    //check if the coordinate is in the tile
                    Utils.Vector2d             coordinate       = Conversions.StringToLatLon(coordinates[i]);
                    Mapbox.Map.UnwrappedTileId coordinateTileId = Conversions.LatitudeLongitudeToTileId(
                        coordinate.x, coordinate.y, tile.CurrentZoom);

                    if (coordinateTileId.Canonical.Equals(tile.CanonicalTileId))
                    {
                        if (String.IsNullOrEmpty(coordinates[i]))
                        {
                            return;
                        }

                        //create new vector feature
                        VectorFeatureUnity feature = new VectorFeatureUnity();
                        feature.Properties = new Dictionary <string, object>();
                        feature.Points     = new List <List <Vector3> >();

                        //create submesh for feature
                        List <Vector3> latLonPoint = new List <Vector3>();
                        //add point to submesh, and submesh to feature
                        latLonPoint.Add(Conversions.LatitudeLongitudeToUnityTilePosition(coordinate, tile.CurrentZoom, tile.TileScale, layer.Extent).ToVector3xz());
                        feature.Points.Add(latLonPoint);

                        //pass valid feature.Data to modifiers
                        //this data has no relation to the features being drawn
                        feature.Data = layer.GetFeature(0);

                        //pass the feature to the mod stack
                        base.Build(feature, tile, tile.gameObject);
                    }
                }
            }
        }
        private void populateCurrentLocation(AndroidJavaObject location)
        {
            if (null == location)
            {
                _currentLocation.IsLocationUpdated    = false;
                _currentLocation.IsUserHeadingUpdated = false;
                return;
            }

            double lat = location.Call <double>("getLatitude");
            double lng = location.Call <double>("getLongitude");

            Utils.Vector2d newLatLng          = new Utils.Vector2d(lat, lng);
            bool           coordinatesUpdated = !newLatLng.Equals(_currentLocation.LatitudeLongitude);

            _currentLocation.LatitudeLongitude = newLatLng;

            float newAccuracy     = location.Call <float>("getAccuracy");
            bool  accuracyUpdated = newAccuracy != _currentLocation.Accuracy;

            _currentLocation.Accuracy = newAccuracy;

            // divide by 1000. Android returns milliseconds, we work with seconds
            long newTimestamp     = location.Call <long>("getTime") / 1000;
            bool timestampUpdated = newTimestamp != _currentLocation.Timestamp;

            _currentLocation.Timestamp = newTimestamp;

            string newProvider     = location.Call <string>("getProvider");
            bool   providerUpdated = newProvider != _currentLocation.Provider;

            _currentLocation.Provider = newProvider;

            bool hasBearing = location.Call <bool>("hasBearing");

            // only evalute bearing when location object actually has a bearing
            // Android populates bearing (which is not equal to device orientation)
            // only when the device is moving.
            // Otherwise it is set to '0.0'
            // https://developer.android.com/reference/android/location/Location.html#getBearing()
            // We don't want that when we rotate a map according to the direction
            // thes user is moving, thus don't update 'heading' with '0.0'
            if (!hasBearing)
            {
                _currentLocation.IsUserHeadingUpdated = false;
            }
            else
            {
                float newHeading = location.Call <float>("getBearing");
                _currentLocation.IsUserHeadingUpdated = newHeading != _currentLocation.UserHeading;
                _currentLocation.UserHeading          = newHeading;
            }

            float?newSpeed     = location.Call <float>("getSpeed");
            bool  speedUpdated = newSpeed != _currentLocation.SpeedMetersPerSecond;

            _currentLocation.SpeedMetersPerSecond = newSpeed;

            // flag location as updated if any of below conditions evaluates to true
            // Debug.LogFormat("coords:{0} acc:{1} time:{2} speed:{3}", coordinatesUpdated, accuracyUpdated, timestampUpdated, speedUpdated);
            _currentLocation.IsLocationUpdated =
                providerUpdated ||
                coordinatesUpdated ||
                accuracyUpdated ||
                timestampUpdated ||
                speedUpdated;

            // Un-comment if required. Throws a warning right now.
            //bool networkEnabled = _gpsInstance.Call<bool>("getIsNetworkEnabled");
            bool gpsEnabled = _gpsInstance.Call <bool>("getIsGpsEnabled");

            if (!gpsEnabled)
            {
                _currentLocation.HasGpsFix        = null;
                _currentLocation.SatellitesInView = null;
                _currentLocation.SatellitesUsed   = null;
            }
            else
            {
                _currentLocation.HasGpsFix = _gpsInstance.Get <bool>("hasGpsFix");
                //int time2firstFix = _gpsInstance.Get<int>("timeToFirstGpsFix");
                _currentLocation.SatellitesInView = _gpsInstance.Get <int>("satellitesInView");
                _currentLocation.SatellitesUsed   = _gpsInstance.Get <int>("satellitesUsedInFix");
            }
        }