public void TestInitFull()
        {
            GeoLocationContext context = new GeoLocationContext()
                                         .SetLatitude(123.564)
                                         .SetLongitude(-12.6)
                                         .SetLatitudeLongitudeAccuracy(5.6)
                                         .SetAltitude(5.5)
                                         .SetAltitudeAccuracy(2.1)
                                         .SetBearing(3.2)
                                         .SetSpeed(100.2)
                                         .SetTimestamp(1234567890000)
                                         .Build();

            Assert.NotNull(context);

            Dictionary <string, object> dict = context.GetData();

            Assert.AreEqual(8, dict.Count);
            Assert.AreEqual(123.564, dict [Constants.GEO_LAT]);
            Assert.AreEqual(-12.6, dict [Constants.GEO_LONG]);
            Assert.AreEqual(5.6, dict [Constants.GEO_LAT_LONG_ACC]);
            Assert.AreEqual(5.5, dict [Constants.GEO_ALT]);
            Assert.AreEqual(2.1, dict [Constants.GEO_ALT_ACC]);
            Assert.AreEqual(3.2, dict [Constants.GEO_BEARING]);
            Assert.AreEqual(100.2, dict [Constants.GEO_SPEED]);
            Assert.AreEqual(1234567890000, dict [Constants.GEO_TIMESTAMP]);

            Assert.AreEqual("iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0", context.GetSchema());
            Assert.AreEqual("{\"data\":{\"latitude\":123.564, \"latitudeLongitudeAccuracy\":5.6, \"altitudeAccuracy\":2.1, \"longitude\":-12.6, \"timestamp\":1234567890000, \"bearing\":3.2, \"speed\":100.2, \"altitude\":5.5}, \"schema\":\"iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0\"}", context.GetJson().ToString());
        }
        public void TestInitMinimal()
        {
            GeoLocationContext context = new GeoLocationContext().SetLatitude(123.564).SetLongitude(-12.6).Build();

            Assert.NotNull(context);

            Dictionary <string, object> dict = context.GetData();

            Assert.AreEqual(2, dict.Count);
            Assert.AreEqual(123.564, dict [Constants.GEO_LAT]);
            Assert.AreEqual(-12.6, dict [Constants.GEO_LONG]);

            Assert.AreEqual("iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0", context.GetSchema());
            Assert.AreEqual("{\"data\":{\"latitude\":123.564, \"longitude\":-12.6}, \"schema\":\"iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0\"}", context.GetJson().ToString());
        }
        public void testInitGeoLocationContext()
        {
            var glc = new GeoLocationContext()
                      .SetLatitude(10.0)
                      .SetLongitude(-10.5)
                      .SetLatitudeLongitudeAccuracy(2564.734124)
                      .SetAltitude(300)
                      .SetAltitudeAccuracy(2)
                      .SetBearing(20.34)
                      .SetSpeed(0.0)
                      .SetTimestamp(123456789123)
                      .Build();

            Assert.IsNotNull(glc);
            Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0"",""data"":{""latitude"":10.0,""longitude"":-10.5,""latitudeLongitudeAccuracy"":2564.734124,""altitude"":300.0,""altitudeAccuracy"":2.0,""bearing"":20.34,""speed"":0.0,""timestamp"":123456789123}}", glc.GetJson().ToString());
        }
        public void TestInitExceptions()
        {
            GeoLocationContext context = null;

            try {
                context = new GeoLocationContext().Build();
            } catch (Exception e) {
                Assert.AreEqual("GeoLocation Context requires 'latitude'.", e.Message);
            }
            Assert.IsNull(context);

            try {
                context = new GeoLocationContext().SetLatitude(123.564).Build();
            } catch (Exception e) {
                Assert.AreEqual("GeoLocation Context requires 'longitude'.", e.Message);
            }
            Assert.IsNull(context);
        }
예제 #5
0
        public IHttpActionResult GetNearByPlaces(double lat, double longitude, int radius)
        {
            var sourcePoint = Common.CreatePoint(lat, longitude);

            var context = new GeoLocationContext();

            // find any locations within 5 kilometers ordered by distance
            List <GeoDistance> matches =
                db.Geos
                .Where(loc => loc.Location.Distance(sourcePoint) < radius)
                .OrderBy(loc => loc.Location.Distance(sourcePoint))
                .Select(loc => new GeoDistance {
                Address = loc.Address, Distance = loc.Location.Distance(sourcePoint)
            }).ToList();


            return(Ok(matches));
        }
예제 #6
0
        // --- ILocationListener Interface

        /// <summary>
        /// Updates the stored GeoLocation context
        /// </summary>
        /// <param name="location"></param>
        public void OnLocationChanged(Location location)
        {
            try
            {
                _geoLocationContext = new GeoLocationContext()
                                      .SetLatitude(location.Latitude)
                                      .SetLongitude(location.Longitude)
                                      .SetAltitude(location.Altitude)
                                      .SetLatitudeLongitudeAccuracy(location.Accuracy)
                                      .SetSpeed(location.Speed)
                                      .SetBearing(location.Bearing)
                                      .SetTimestamp(location.Time)
                                      .Build();
            }
            catch
            {
                _geoLocationContext = null;
            }
        }
 private void LocationUpdated(CLLocation location)
 {
     try
     {
         GeoLocationContext = new GeoLocationContext()
                              .SetLatitude(location.Coordinate.Latitude)
                              .SetLongitude(location.Coordinate.Longitude)
                              .SetAltitude(location.Altitude)
                              .SetLatitudeLongitudeAccuracy(location.HorizontalAccuracy)
                              .SetSpeed(location.Speed)
                              .SetBearing(location.Course)
                              .SetTimestamp(NSDateToUnixEpoch(location.Timestamp))
                              .Build();
     }
     catch
     {
         GeoLocationContext = null;
     }
 }
예제 #8
0
 public GeoLocationsController(GeoLocationContext context)
 {
     _context = context;
 }
예제 #9
0
        /// <summary>
        /// Adds the standard NV Pairs to the payload and stitches any available
        /// contexts to the final payload.
        /// </summary>
        /// <param name="payload">The basee event payload</param>
        /// <param name="contexts">The contexts array</param>
        /// <param name="eventId">The event ID</param>
        private void CompleteAndTrackPayload(Payload payload, List <IContext> contexts, string eventId)
        {
            payload.AddDict(_standardNvPairs);

            // Add the subject data if available
            if (_subject != null)
            {
                payload.AddDict(_subject._payload.Payload);
            }

            // Add the session context if available
            if (_clientSession != null)
            {
                contexts.Add(_clientSession.GetSessionContext(eventId));
            }

            // Add the desktop context if available
            if (_desktopContextDelegate != null)
            {
                DesktopContext desktopContext = _desktopContextDelegate.Invoke();
                if (desktopContext != null)
                {
                    contexts.Add(desktopContext);
                }
            }

            // Add the mobile context if available
            if (_mobileContextDelegate != null)
            {
                MobileContext mobileContext = _mobileContextDelegate.Invoke();
                if (mobileContext != null)
                {
                    contexts.Add(mobileContext);
                }
            }

            // Add the geo-location context if available
            if (_geoLocationDelegate != null)
            {
                GeoLocationContext geoLocationContext = _geoLocationDelegate.Invoke();
                if (geoLocationContext != null)
                {
                    contexts.Add(geoLocationContext);
                }
            }

            // Build the final context and it to the payload
            if (contexts != null && contexts.Any())
            {
                var contextArray = new List <Dictionary <string, object> >();
                foreach (IContext context in contexts)
                {
                    contextArray.Add(context.GetJson().Payload);
                }
                var contextEnvelope = new SelfDescribingJson(Constants.SCHEMA_CONTEXTS, contextArray);
                payload.AddJson(contextEnvelope.Payload, _encodeBase64, Constants.CONTEXT_ENCODED, Constants.CONTEXT);
            }

            // Send the payload to the emitter
            if (_synchronous)
            {
                _emitter.Input(payload);
            }
            else
            {
                Task.Factory.StartNew(() => _emitter.Input(payload));
            }
        }