Exemplo n.º 1
0
        public bool AddToLogCurrentInfo(GpsPosition data)
        {
            if (string.IsNullOrEmpty(LogDb))
            {
                return(false);
            }

            bool ret = true;

            try
            {
                {
                    if (cmd.Transaction == null)
                    {
                        cmd.Transaction = cn.BeginTransaction(IsolationLevel.Serializable);
                        Debug.WriteLine("BeginTransaction: " + DateTime.Now.ToLongTimeString());
                    }

                    cmd.Parameters["@p1"].Value  = data.Time.Value;
                    cmd.Parameters["@p2"].Value  = countReal++;
                    cmd.Parameters["@p3"].Value  = Delta;
                    cmd.Parameters["@p4"].Value  = data.Speed;
                    cmd.Parameters["@p5"].Value  = data.SeaLevelAltitude;
                    cmd.Parameters["@p6"].Value  = data.EllipsoidAltitude;
                    cmd.Parameters["@p7"].Value  = (short?)data.SatellitesInViewCount;
                    cmd.Parameters["@p8"].Value  = (short?)data.SatelliteCount;
                    cmd.Parameters["@p9"].Value  = data.Latitude.Value;
                    cmd.Parameters["@p10"].Value = data.Longitude.Value;
                    cmd.Parameters["@p11"].Value = data.PositionDilutionOfPrecision;
                    cmd.Parameters["@p12"].Value = data.HorizontalDilutionOfPrecision;
                    cmd.Parameters["@p13"].Value = data.VerticalDilutionOfPrecision;
                    cmd.Parameters["@p14"].Value = (byte)data.FixQuality;
                    cmd.Parameters["@p15"].Value = (byte)data.FixType;
                    cmd.Parameters["@p16"].Value = (byte)data.FixSelection;

                    cmd.ExecuteNonQuery();
                }

                if (DateTime.Now - LastFlush >= FlushDelay)
                {
                    TryCommitData();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AddToLog: " + ex.ToString());
                ret = false;
            }

            return(ret);
        }
Exemplo n.º 2
0
        public void SerialGps_Position_Basic()
        {
            var x = new GpsPosition(45.5575, 18.6796, 87);

            Assert.AreEqual(45.5575, x.Latitude);
            Assert.AreEqual(18.6796, x.Longitude);
            Assert.AreEqual(87, x.Altitude);

            Assert.IsTrue(x.HasLongitude);
            Assert.IsTrue(x.HasLatitude);
            Assert.IsTrue(x.HasAltitude);

            Assert.AreEqual("45.5575° N, 18.6796° E", x.ToString());
        }
Exemplo n.º 3
0
        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            position = args.Position;

            // call the UpdateData method via the updateDataHandler so that we
            // update the UI on the UI thread
            try
            {
                BeginInvoke(updateDataHandler);
            }
            catch (NullReferenceException)
            {
            }
        }
        public void SetGpsPositionDate(DateTime utcTime)
        {
            this.gpsPositionMiddle = new GpsPosition();

            // Ensure Points are valid and utcTime is inbetween the two points
            if (this.GpsPositionBefore.IsValidCoordinate &&
                this.GpsPositionAfter.IsValidCoordinate &&
                this.GpsPositionBefore.Time < utcTime &&
                this.GpsPositionAfter.Time > utcTime)
            {
                // Set common properties
                this.gpsPositionMiddle.Source = this.GpsPositionAfter.Source;

                // Work out the difference between the two points in nano seconds
                long nanoSecondsGap = this.GpsPositionAfter.Time.Ticks - this.GpsPositionBefore.Time.Ticks;

                // Work out LatLong distance between the two points
                double latDistance  = this.GpsPositionAfter.Latitude.Numeric - this.GpsPositionBefore.Latitude.Numeric;
                double longDistance = this.GpsPositionAfter.Longitude.Numeric - this.GpsPositionBefore.Longitude.Numeric;
                double elevDistance = this.GpsPositionAfter.Altitude - this.GpsPositionBefore.Altitude;

                long nanoSecondsPhoto = utcTime.Ticks - this.GpsPositionBefore.Time.Ticks;

                // Work out the new values using the % difference between the two points and add this to the first point
                // Round Lat\Long to 6 decimals and altitude to 3
                if (nanoSecondsGap == 0)
                {
                    this.gpsPositionMiddle.Latitude.Numeric  = this.GpsPositionBefore.Latitude.Numeric;
                    this.gpsPositionMiddle.Longitude.Numeric = this.GpsPositionBefore.Longitude.Numeric;
                    this.gpsPositionMiddle.Altitude          = this.GpsPositionBefore.Altitude;
                }
                else
                {
                    this.gpsPositionMiddle.Latitude.Numeric  = Math.Round((latDistance * nanoSecondsPhoto / nanoSecondsGap) + this.GpsPositionBefore.Latitude.Numeric, 6);
                    this.gpsPositionMiddle.Longitude.Numeric = Math.Round((longDistance * nanoSecondsPhoto / nanoSecondsGap) + this.GpsPositionBefore.Longitude.Numeric, 6);
                    this.gpsPositionMiddle.Altitude          = Math.Round((elevDistance * nanoSecondsPhoto / nanoSecondsGap) + this.GpsPositionBefore.Altitude, 3);
                }

                // Set the match time based on the closest satellite
                if (this.GpsPositionBefore.Time.Ticks - utcTime.Ticks > utcTime.Ticks - this.GpsPositionAfter.Time.Ticks)
                {
                    this.gpsPositionMiddle.Time = this.GpsPositionBefore.Time;
                }
                else
                {
                    this.gpsPositionMiddle.Time = this.GpsPositionAfter.Time;
                }
            }
        }
    // Applies other player's GPS and orientation values to this player object that were synced across the network
    // Function only called by non-local players
    private void ApplyNetworkPlayerValues()
    {
        // Converts the GPS struct value synced across the network back into Sturfee class 'GpsPosition'
        // to correctly sync this players position in the world.
        var gps = new GpsPosition
        {
            Latitude  = PlayerGpsPos.Latitude,
            Longitude = PlayerGpsPos.Longitude,
            Height    = PlayerGpsPos.Height
        };

        // Converts the GPS position to this client player's Unity coordinates
        transform.position = XRSessionManager.GetSession().GpsToLocalPosition(gps);
        transform.rotation = PlayerOrientation;
    }
Exemplo n.º 6
0
    // Takes the synced GPS position and converts them to this client player's Unity coordinates
    private void AdjustTargetToPlayerCoordinates()
    {
        var gps = new GpsPosition
        {
            Latitude  = GpsPos.Latitude,
            Longitude = GpsPos.Longitude,
            Height    = GpsPos.Height
        };

        transform.position = XRSessionManager.GetSession().GpsToLocalPosition(gps);
        transform.rotation = Orientation;

        // Rotate the map representation of the target independently to have correct orientation on map view
        MapTarget.transform.rotation = Quaternion.identity;
    }
Exemplo n.º 7
0
        public void Add(GpsPosition position)
        {
            base.Add(position);

            if (position.LatitudeValid && position.LongitudeValid)
            {
                if (position.SeaLevelAltitudeValid)
                {
                    geoCoordinateList.Add(new Coordinates.Coordinate(new Geometry.Point((float)(position.Latitude), (float)(position.Longitude)), false));
                }
                else
                {
                    geoCoordinateList.Add(new Coordinates.Coordinate(new Geometry.Point((float)(position.Latitude), (float)(position.Longitude), (float)(position.SeaLevelAltitude)), true));
                }
            }
        }
Exemplo n.º 8
0
    public static float DistanceTo(GpsPosition localPosition, GpsPosition targetPosition)
    {
        double rlat1  = Mathf.PI * localPosition.Latitude / 180;
        double rlat2  = Mathf.PI * targetPosition.Latitude / 180;
        double theta  = localPosition.Longitude - targetPosition.Longitude;
        double rtheta = Mathf.PI * theta / 180;
        double dist   =
            Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) *
            Math.Cos(rlat2) * Math.Cos(rtheta);

        dist = Math.Acos(dist);
        dist = dist * 180 / Mathf.PI;
        dist = dist * 60 * 1.853159616f;

        return((float)dist);
    }
    public override GpsPosition GetGPSPosition()
    {
        if (_providerStatus != ProviderStatus.Ready)
        {
            Debug.Log("Sample GPsProvider is not yet ready");
            return(null);
        }

        GpsPosition gpsPosition = new GpsPosition
        {
            Latitude  = _sampleManage.GetDataAtCurrentIndex().latitude,
            Longitude = _sampleManage.GetDataAtCurrentIndex().longitude,
            Height    = _sampleManage.GetDataAtCurrentIndex().height
        };

        return(gpsPosition);
    }
Exemplo n.º 10
0
        public void WriteGpsMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            // Test data, includes Unicode strings
            GpsPosition positionCreated = new GpsPosition(101.23, -34.321, -99.8);
            GpsPosition positionShow    = new GpsPosition(-123.0, 179);

            // Scrub existing data
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // Check for empty data
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "Blank GpsPosition Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "Blank GpsPosition Shown");

            // Write GpsPosition Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = positionCreated;
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // And Check Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, positionCreated, "WriteCreated Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "WriteCreated Shown");

            // Write GpsPosition Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = positionShow;
            testPhoto.WriteMetadata();

            // And Check Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "WriteShown Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, positionShow, "WriteShown Shown");

            // Tidy up
            File.Delete(testPhoto.FileFullName);
        }
Exemplo n.º 11
0
        void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            GpsPosition    position = args.Position;
            ControlUpdater cu       = UpdateControl;

            if ((position.LatitudeValid) & (position.LongitudeValid))
            {
                statusBar1.Visible = true;
                statusBar1.Text    = "Localização identificada.";
                Invoke(cu, begLat, position.Latitude.ToString());
                Invoke(cu, begLng, position.Longitude.ToString());
                gps.LocationChanged -= gps_LocationChanged;
                gm.setLatitude(position.Latitude);
                gm.setLongitude(position.Longitude);
                mapBox.Image = gm.RetrieveStaticMap();
            }
        }
Exemplo n.º 12
0
        //execute if location is changed to update form component and save data to database
        public void Form1_NewLocationReceived(object sender, LocationChangedEventArgs e)
        {
            if (!gpsConnector.isClosingGps)
            {
                GpsPosition position = e.Position;
                try
                {
                    //check gps connection - if gps not open then open gps
                    gpsConnector.openGps();

                    //retrive position to save gps data to database
                    gpsConnector.retrivePosition(position);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("new loc" + ex.Message);
                }
            }
        }
Exemplo n.º 13
0
    public static float AngleTo(GpsPosition localPosition, GpsPosition targetPosition)
    {
        localPosition.Latitude   *= Mathf.Deg2Rad;
        targetPosition.Latitude  *= Mathf.Deg2Rad;
        localPosition.Longitude  *= Mathf.Deg2Rad;
        targetPosition.Longitude *= Mathf.Deg2Rad;

        double dLon = (targetPosition.Longitude - localPosition.Longitude);
        double y    = Math.Sin(dLon) * Math.Cos(targetPosition.Latitude);
        double x    = (Math.Cos(localPosition.Latitude) * Math.Sin(targetPosition.Latitude)) -
                      (Math.Sin(localPosition.Latitude) * Math.Cos(targetPosition.Latitude) * Math.Cos(dLon));
        double brng = Math.Atan2(y, x);

        brng = Mathf.Rad2Deg * brng;
        brng = (brng + 360) % 360;
        brng = 360 - brng;

        return((float)brng);
    }
    public static void LoadGameData()
    {
        for (int i = 0; i < ArItemList.Count; i++)
        {
            // Convert serialized data back into usaarItemDatable data objects

            ArItemData arItemData = ArItemList [i];

            Quaternion quat = arItemData.Orientation.GetQuaternion;

            GpsSerializable gpsPos = arItemData.GpsPos;
            var             gps    = new GpsPosition
            {
                Latitude  = gpsPos.Latitude,
                Longitude = gpsPos.Longitude,
                Height    = gpsPos.Height
            };
            Vector3 pos = XRSessionManager.GetSession().GpsToLocalPosition(gps);


//			GameObject spawnItem;
//			if (arItemData.ItemType == (int)ArItemType.tier1)
//			{
//				spawnItem = GameManager.Instance.Tier1ItemPrefab;
//			}
//			else if (arItemData.ItemType == (int)ArItemType.tier2)
//			{
//				spawnItem = GameManager.Instance.Tier2ItemPrefab;
//			}
//			else
//			{
//				spawnItem = GameManager.Instance.Tier3ItemPrefab;
//			}
//

            //PlayerMapTouchController.Instance.SpawnSavedFlag (pos, quat, arItemData.Id);

//			GameObject arItem = Instantiate (PlayerMapTouchController.Instance.FlagPrefab, pos, quat);
//			arItem.GetComponent<ArItem> ().Id = arItemData.Id;
        }
    }
Exemplo n.º 15
0
    private void Update()
    {
        if (Time.time - _startTime < Delay)
        {
            _testGps       = null;
            ProviderStatus = ProviderStatus.Initializing;
            return;
        }

        if (_testGps == null)
        {
            _testGps = new GpsPosition()
            {
                Latitude  = Latitude,
                Longitude = Longitude,
                Height    = Height
            };

            ProviderStatus = ProviderStatus.Ready;
        }
    }
Exemplo n.º 16
0
        public void FindGpsPositionCreated(JpgPhoto photo, bool reparse)
        {
            // Reset Data
            if (reparse)
            {
                photo.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            }

            // Use Gpx Tracks if Configured
            if (!photo.Metadata.GpsPositionOfLocationCreated.IsValidCoordinate && this.IsGpxTracksResolverConfigured)
            {
                if (photo.Metadata.DateUtc == null || photo.Metadata.DateUtc == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                GpsPosition gpsPosition = this.gpxTrackResolver.FindGpsPosition(photo.Metadata.DateUtc);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    photo.Metadata.GpsPositionOfLocationCreated = gpsPosition;
                }
            }

            // Use Nmea Tracks if Configured
            if (!photo.Metadata.GpsPositionOfLocationCreated.IsValidCoordinate && this.IsNmeaTracksResolverConfigured)
            {
                if (photo.Metadata.DateUtc == null || photo.Metadata.DateUtc == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                GpsPosition gpsPosition = this.nmeaTrackResolver.FindGpsPosition(photo.Metadata.DateUtc);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    photo.Metadata.GpsPositionOfLocationCreated = gpsPosition;
                }
            }
        }
Exemplo n.º 17
0
        private void position2XMLFile(GpsPosition position)
        {
            DateTime dateTime1;

            using (StreamWriter streamWriter1 = new StreamWriter("bcPosition.xml"))
            {
                streamWriter1.WriteLine("<?xml version0x03d\"1.0\"?>");
                streamWriter1.WriteLine("<position>");
                streamWriter1.Write("<latitude>");
                streamWriter1.Write(position.Latitude);
                streamWriter1.WriteLine("</latitude>");
                streamWriter1.Write("<longitude>");
                streamWriter1.Write(position.Longitude);
                streamWriter1.WriteLine("</longitude>");
                streamWriter1.Write("<speed>");
                streamWriter1.Write(position.Speed);
                streamWriter1.WriteLine("</speed>");
                streamWriter1.Write("<cog>");
                streamWriter1.Write(position.Heading);
                streamWriter1.WriteLine("</cog>");
                streamWriter1.Write("<elev>");
                streamWriter1.Write(position.SeaLevelAltitude);
                streamWriter1.WriteLine("</elev>");
                streamWriter1.Write("<satsolution>");
                streamWriter1.Write(position.SatelliteCount);
                streamWriter1.WriteLine("</satsolution>");
                streamWriter1.Write("<ticks>");
                dateTime1 = position.Time;
                streamWriter1.Write(dateTime1.Ticks);
                streamWriter1.WriteLine("</ticks>");
                streamWriter1.Write("<jsdate>");
                streamWriter1.Write(((dateTime1 = position.Time).ToString("MM\'/\'dd\'/\'yyyy hh:mm:ss") + " UTC+0000"));
                streamWriter1.WriteLine("</jsdate>");
                streamWriter1.Write("<isodate>");
                streamWriter1.Write(((dateTime1 = position.Time).ToString("s") + "Z"));
                streamWriter1.WriteLine("</isodate>");
                streamWriter1.WriteLine("</position>");
            }
        }
Exemplo n.º 18
0
        public void HandleNewPosition(GpsPosition pos)
        {
            if (!pos.LatitudeValid || !pos.LongitudeValid)
            {
                this.lblLatLang.Text = "N/A";
            }
            else
            {
                this.lblLatLang.Text = "Lat:" + String.Format("{0:0.00000}", pos.Latitude) + "  Lng:" + String.Format("{0:0.00000}", pos.Longitude);
            }

            if (!pos.TimeValid)
            {
                this.lblTime.Text = "...";
            }
            else
            {
                this.lblTime.Text = pos.Time.ToString();
            }

            if (!pos.SpeedValid)
            {
                this.lblSpeed.Text = "...";
            }
            else
            {
                float speed = (float)(pos.Speed * 1.85200);
                this.lblSpeed.Text = String.Format("{0:0.0}", speed);
            }

            if (!pos.HeadingValid)
            {
                this.lblHeading.Text = "Heading\n...";
            }
            else
            {
                this.lblHeading.Text = "Heading\n" + pos.Heading + " deg";
            }
        }
Exemplo n.º 19
0
        public string SaveData([FromBody] JObject rawPayLoad)
        {
            RawPayLoad loraData = JsonConvert.DeserializeObject <RawPayLoad>(rawPayLoad.ToString());

            //TheThingNetwork send the EUI in the pay_load data
            //EUI is the link between Lora chip and User
            GpsPosition GpsData = new GpsPosition()
            {
                DeviceId             = DbContext.Device.Where(p => p.DeviceEUI == loraData.Hardware_serial).Select(p => p.DeviceId).FirstOrDefault(),
                GpsPositionLatitude  = DegreeToDecimal(loraData.Payload_fields.Latitude, loraData.Payload_fields.LatitudeDecimal),
                GpsPositionLongitude = DegreeToDecimal(loraData.Payload_fields.Longitude, loraData.Payload_fields.LongitudeDecimal),
                GpsPositionDate      = loraData.Metadata.Time,

                //For debugging
                GpsPositionLatitudeRaw  = string.Format("{0}.{1}", loraData.Payload_fields.Latitude, loraData.Payload_fields.LatitudeDecimal),
                GpsPositionLongitudeRaw = string.Format("{0}.{1}", loraData.Payload_fields.Longitude, loraData.Payload_fields.LongitudeDecimal)
            };

            DbContext.Add(GpsData);
            DbContext.SaveChanges();
            return("Saved");
        }
Exemplo n.º 20
0
 //retrive gps position to save into database and display in parent form
 public void retrivePosition(GpsPosition position)
 {
     try
     {
         //if satellite info is avaliable
         if (position.SatellitesInSolutionValid && position.SatelliteCountValid && position.SatellitesInViewValid)
         {
             if (position.PositionDilutionOfPrecisionValid && position.PositionDilutionOfPrecision < 7)
             {
                 //add position to position list
                 parentForm.gpsPositionList.Add(position);
             }
             //set satellite data in satView
             satView.setSatellite(position);
             //display on form components
             parentForm.updateForm(position);
         }
     }catch (Exception ex)
     {
         MessageBox.Show("mess retr" + ex.Message);
     }
 }
Exemplo n.º 21
0
    private void CheckDistance()
    {
        if (!_checkGps)
        {
            return;
        }

        _timeSinceLastCheck += Time.deltaTime;

        if (_timeSinceLastCheck < _checkGpsDelayInSec)
        {
            return;
        }

        _timeSinceLastCheck -= _checkGpsDelayInSec;

        if (Input.location.status == LocationServiceStatus.Running)
        {
            var locationData = new GpsPosition(Input.location.lastData.latitude, Input.location.lastData.longitude);
            var distance     = GpsHelper.DistanceTo(locationData, _targetPosition);

            _distanceText.text = GpsHelper.DistanceToString(distance);

            if (distance < _unlockDistanceInKm)
            {
                UnlockAnimation();
            }
        }
        else if (Input.location.status == LocationServiceStatus.Stopped)
        {
            Input.location.Start();
        }
        else if (Input.location.status == LocationServiceStatus.Failed)
        {
            _distanceText.text = "NO GPS";

            _checkGps = false;
        }
    }
Exemplo n.º 22
0
        private void EditGps(PlayModeStateChange state)
        {
            WorldAnchor worldAnchor = (WorldAnchor)target;

            if (state == PlayModeStateChange.ExitingPlayMode)
            {
                // Save current GPSPosition of target WorldAnchor to EditorPrefs
                string saveKey       = "WorldAnchorSaveData_" + worldAnchor.GetInstanceID();
                string serializedGPS = EditorJsonUtility.ToJson(worldAnchor.GpsPosition);
                EditorPrefs.SetString(saveKey, serializedGPS);
            }

            if (state == PlayModeStateChange.EnteredEditMode)
            {
                // Assign GPSPosition to all the worldAnchors in the scene by reading its value from EditorPrefs
                foreach (WorldAnchor wa in FindObjectsOfType <WorldAnchor>())
                {
                    string savedKey = "WorldAnchorSaveData_" + wa.GetInstanceID();
                    if (EditorPrefs.HasKey(savedKey))
                    {
                        string serializedGPS = EditorPrefs.GetString(savedKey);
                        var    updatedGps    = new GpsPosition();
                        EditorJsonUtility.FromJsonOverwrite(serializedGPS, updatedGps);

                        // Disconnect Prefab connection(if any) otherwise values will reset to what it was before Play
                        if (PrefabUtility.GetPrefabType(wa) == PrefabType.PrefabInstance)
                        {
                            PrefabUtility.DisconnectPrefabInstance(wa);
                        }

                        wa.GpsPosition = updatedGps;
                    }
                }
            }

            worldAnchor._editGPS = false;
        }
    public static void LoadGameData()
    {
        for (int i = 0; i < ArItemList.Count; i++)
        {
            // Convert serialized data back into usable data objects

            ArItemData arItemData = ArItemList [i];

            Quaternion quat = arItemData.Orientation.GetQuaternion;

            GpsSerializable gpsPos = arItemData.GpsPos;
            var             gps    = new GpsPosition
            {
                Latitude  = gpsPos.Latitude,
                Longitude = gpsPos.Longitude,
                Height    = gpsPos.Height
            };
            Vector3 pos = XRSessionManager.GetSession().GpsToLocalPosition(gps);

            GameObject spawnItem;
            if (arItemData.ItemType == (int)ArItemType.level1)
            {
                spawnItem = GameManager.Instance.Level1ItemPrefab;
            }
            else if (arItemData.ItemType == (int)ArItemType.level2)
            {
                spawnItem = GameManager.Instance.Level2ItemPrefab;
            }
            else
            {
                spawnItem = GameManager.Instance.Level3ItemPrefab;
            }

            GameObject arItem = Instantiate(spawnItem, pos, quat);
            arItem.GetComponent <ArItem> ().Id = arItemData.Id;
        }
    }
Exemplo n.º 24
0
    public void Shoot()
    {
        var gps = new GpsPosition
        {
            Latitude  = GpsPos.Latitude,
            Longitude = GpsPos.Longitude,
            Height    = GpsPos.Height
        };

        transform.position = XRSessionManager.GetSession().GpsToLocalPosition(gps);

        GetComponent <Collider> ().enabled   = true;
        GetComponent <Rigidbody> ().velocity = Direction * Speed;

        Destroy(this.gameObject, 3.0f);

        if (!RaycastShot)
        {
            _curYAdjust     = 0;
            _adjustPerFrame = 0.005f;

            StartCoroutine(RaiseBullet());
        }
    }
Exemplo n.º 25
0
        public void AddToForwardCacheRecords(Address address, GpsPosition gpsPosition, DateTime date)
        {
            GpsPosition existingGpsPosition = this.FindGpsPosition(address);

            // Remove existing entry
            if (existingGpsPosition != null)
            {
                var query = from x in this.cachedForwardRecords
                            where x.Address.HierarchicalName.ToLower() == address.HierarchicalName.ToLower()
                            select x;

                this.cachedForwardRecords.Remove(query.First());
            }

            GeoCacheRecord cachedResult = new GeoCacheRecord();

            cachedResult.Address     = address.Clone() as Address;
            cachedResult.Date        = date;
            cachedResult.GpsPosition = gpsPosition.Clone() as GpsPosition;

            this.cachedForwardRecords.Add(cachedResult);

            this.WriteCachedRecords(this.cacheForwardFileName, this.cachedForwardRecords, true);
        }
Exemplo n.º 26
0
        public GpsPosition FindGpsPosition(DateTime utcDate)
        {
            GpsPosition gpsPosition = new GpsPosition();

            if (this.IsGpxTracksResolverConfigured)
            {
                if (utcDate == null || utcDate == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                gpsPosition = this.gpxTrackResolver.FindGpsPosition(utcDate);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    return(gpsPosition);
                }
            }

            if (this.IsNmeaTracksResolverConfigured)
            {
                if (utcDate == null || utcDate == new DateTime())
                {
                    throw new Exception("Metadata.UtcDate must be set Gps Tracks are UTC based");
                }

                gpsPosition = this.nmeaTrackResolver.FindGpsPosition(utcDate);

                if (gpsPosition != null && gpsPosition.IsValidCoordinate)
                {
                    return(gpsPosition);
                }
            }

            return(new GpsPosition());
        }
Exemplo n.º 27
0
        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            try
            {
                position = args.Position;
                if (position != null)
                {
                    if (position.LatitudeValid && position.LongitudeValid)
                    {
                        this.gk = mainControler.CoordCalculator.GeoGkGDAL(position, config.CoordGaußKruegerStripe);

                        if (_updateAsDataComes)
                        {
                            OnPositionChanged();
                            updateSceen(null);
                        }
                    }
                }
            }
            catch
            {
                // if something is going wrong here, we have a serious problem
            }
        }
Exemplo n.º 28
0
    private IEnumerator GetVenueData(GpsPosition gpsPos)
    {
        OnVenuesCallStarted();

        string url = "https://api.foursquare.com/v2/venues/search?ll=" + gpsPos.Latitude.ToString() + "," + gpsPos.Longitude.ToString()
                     + "&radius=" + _radius.ToString() + _urlTail;

        using (UnityWebRequest www = UnityWebRequest.Get(url))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
                OnVenuesCallFailed();
            }
            else
            {
                var d = JsonUtility.FromJson <FoursquareAPI.RootObject>(www.downloadHandler.text);
                List <FoursquareAPI.Venue> venues = d.response.venues;
                OnVenuesReceived(GetSortedArrayFromData(venues));
            }
        }
    }
Exemplo n.º 29
0
 private void GPS_PositionReceived(string Lat, string Lon)
 {
     if (OSGconv.ParseNMEA(Lat, Lon, 0))
     {
         GpsPosition pos = new GpsPosition(Convert.ToString(OSGconv.deciLat), Convert.ToString(OSGconv.deciLon));
         string strToSend = JsonConvert.SerializeObject(pos);
         Debug.WriteLine("GPSService => " + strToSend);
         this.Send(strToSend);
     }
 }
Exemplo n.º 30
0
        protected void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            try
            {
                position = args.Position;
                if (position != null)
                {
                    if (position.LatitudeValid && position.LongitudeValid)
                    {
                        this.gk = mainControler.CoordCalculator.GeoGkGDAL(position, config.CoordGaußKruegerStripe);

                        if (_updateAsDataComes) {
                            OnPositionChanged();
                            updateSceen(null);
                        }
                    }
                }
            }
            catch
            {
               // if something is going wrong here, we have a serious problem
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Get the position reported by the GPS receiver that is no older than
        /// the maxAge passed in
        /// </summary>
        /// <param name="maxAge">Max age of the gps position data that you want back. 
        /// If there is no data within the required age, null is returned.  
        /// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param>
        /// <returns>GpsPosition class with all the position details</returns>
        public GpsPosition GetPosition(TimeSpan maxAge)
        {
            GpsPosition gpsPosition = null;
            if (Opened)
            {
                // allocate the necessary memory on the native side.  We have a class (GpsPosition) that
                // has the same memory layout as its native counterpart
                IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition)));

                // fill in the required fields
                gpsPosition = new GpsPosition();
                gpsPosition.dwVersion = 1;
                gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition));

                // Marshal our data to the native pointer we allocated.
                Marshal.StructureToPtr(gpsPosition, ptr, false);

                // call native method passing in our native buffer
                int result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
                if (result == 0)
                {
                    // native call succeeded, marshal native data to our managed data
                    gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));

                    if (maxAge != TimeSpan.Zero)
                    {
                        // check to see if the data is recent enough.
                        if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
                        {
                            gpsPosition = null;
                        }
                    }
                }

                // free our native memory
                Utils.LocalFree(ptr);
            }

            return gpsPosition;
        }
Exemplo n.º 32
0
        private void GPS_PositionReceived(string Lat, string Lon)
        {
            if (OSGconv.ParseNMEA(Lat, Lon, 0))
            {
                GpsPosition pos = new GpsPosition(Convert.ToString(OSGconv.deciLat), Convert.ToString(OSGconv.deciLon));
                string strToSend = JsonConvert.SerializeObject(pos);
                Debug.WriteLine("GPS_PositionReceived => " + strToSend);
                this.Send(strToSend);
                //deleInvokeMapControlPos dele = delegate(string _lat, string _lon)
                //{
                //    this.txtLat.Text = _lat;
                //    this.txtLng.Text = _lon;
                //};
                //if (this.stop_receive == false)
                //{

                //    this.Invoke(dele, (Convert.ToString(OSGconv.deciLat)), (Convert.ToString(OSGconv.deciLon)));
                //}
            }
        }
Exemplo n.º 33
0
        public Fotofly.Address FindAddress(GpsPosition gpsPosition, string country, bool useCache)
        {
            Fotofly.Address returnValue = new Fotofly.Address();

            // Check Resolver Cache
            if (this.resolverCache != null && useCache)
            {
                returnValue = this.resolverCache.FindAddress(gpsPosition);

                if (returnValue != null && returnValue.IsValidAddress)
                {
                    return(returnValue);
                }
            }

            // Reset incase null from above
            returnValue = new Fotofly.Address();

            // Set the LatLong
            LatLong latLong = new LatLong();

            latLong.Latitude  = gpsPosition.Latitude.Numeric;
            latLong.Longitude = gpsPosition.Longitude.Numeric;

            // Set the datasource
            BingMapsDataSources dataSource = this.LiveMapsDataSource(country);

            GetInfoOptions options = new GetInfoOptions();

            options.IncludeAddresses      = true;
            options.IncludeAllEntityTypes = false;

            GetLocationInfoRequest infoRequest = new GetLocationInfoRequest();

            infoRequest.dataSourceName = "MapPoint." + dataSource.ToString();
            infoRequest.options        = options;
            infoRequest.location       = latLong;

            Location[] places = null;

            try
            {
                places = this.findService.GetLocationInfo(null, null, latLong, infoRequest.dataSourceName, options);
            }
            catch (EndpointNotFoundException e)
            {
                throw new Exception("Unable to find\\connect to Bing Map WebService", e);
            }
            catch (TimeoutException e)
            {
                throw new Exception("Bing Map call timed out", e);
            }
            catch (Exception e)
            {
                places = null;
            }

            if (places != null && places.Length > 0 && places[0].Address != null)
            {
                returnValue.Country     = places[0].Address.CountryRegion;
                returnValue.Region      = this.LookupRegionName(places[0].Address.Subdivision, returnValue.Country);
                returnValue.City        = places[0].Address.PrimaryCity;
                returnValue.AddressLine = places[0].Address.AddressLine;
            }
            else
            {
                // Add to Failure to cache
                if (this.resolverCache != null)
                {
                    this.resolverCache.AddToReverseFailedRecords(gpsPosition);
                }
            }

            return(returnValue);
        }
Exemplo n.º 34
0
 public Fotofly.Address FindAddress(GpsPosition gpsPosition, string country)
 {
     return(this.FindAddress(gpsPosition, country, true));
 }
Exemplo n.º 35
0
        void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            position = args.Position;

            // call the UpdateData method via the updateDataHandler so that we
            // update the UI on the UI thread
            try
            {
                Invoke(UpdateGpsDataHandler);
            }
            catch { }
        }
Exemplo n.º 36
0
 public LocationChangedEventArgs(GpsPosition position)
 {
     this.position = position;
 }