public List <string> GetConnections(double latitude, double longitude)
        {
            List <string> conn  = new List <string>();
            var           point = new Position(latitude, longitude);

            try
            {
                lock (coordUser)
                {
                    foreach (var p in coordUser)
                    {
                        var test = GeoHelper.CalculateDistance(point, p.Value);
                        if (GeoHelper.CalculateDistance(point, p.Value) < 15000)
                        {
                            conn.Add(p.Key);
                        }
                    }
                }
            }
            catch
            {
                conn = null;
            }
            return(conn);
        }
Esempio n. 2
0
 public bool ValidateRestrictedArea(Observation observation)
 {
     if (this.Mission.RestrictedArea != null)
     {
         if (this.Mission.RestrictedArea.GetType() == typeof(CircleArea))
         {
             CircleArea cirleArea = (CircleArea)this.Mission.RestrictedArea;
             double     distance  = GeoHelper.CalculateDistance(new Position(cirleArea.Center.Coordinates.Latitude, cirleArea.Center.Coordinates.Longitude), new Position(observation.Coordinates.Coordinates.Latitude, observation.Coordinates.Coordinates.Longitude));
             return(distance < cirleArea.Radius);
         }
         else
         {
             PolygonArea polygonArea = (PolygonArea)this.Mission.RestrictedArea;
             return(GeoHelper.IsPointInPolygon(polygonArea.Polygon.Coordinates.Exterior.Positions.Select(x => new Position(x.Latitude, x.Longitude)).ToArray(), new Position(observation.Coordinates.Coordinates.Latitude, observation.Coordinates.Coordinates.Longitude)));
         }
     }
     return(true);
 }
Esempio n. 3
0
        public async Task <JsonResult> GetPlaceDetails(String placeId, Double latitude, Double longitude)
        {
            try
            {
                IMongoCollection <ReadPlace> places    = _database.GetCollection <ReadPlace>("places");
                IMongoCollection <Review>    reviews   = _database.GetCollection <Review>("reviews");
                IMongoCollection <Country>   countries = _database.GetCollection <Country>("countries");
                var place = await places.Aggregate().Match(x => x.Id == ObjectId.Parse(placeId)).Lookup <ReadPlace, Review, BsonDocument>(reviews, x => x.Id, y => y.PlaceId, d => d["reviews"])
                            .Unwind(x => x["reviews"], new AggregateUnwindOptions <BsonDocument>()
                {
                    PreserveNullAndEmptyArrays = true
                })
                            .Group(new BsonDocument()
                {
                    { "_id", new BsonDocument()
                      {
                          { "placeId", "$placeId" },
                          { "description", "$description" },
                          { "phoneNumber", "$phoneNumber" },
                          { "address", "$address" },
                          { "website", "$website" },
                          { "name", "$name" },
                          { "openingHours", "$openingHours" },
                          { "tags", "$tags" },
                          { "type", "$type" },
                          { "gallery", "$gallery" },
                          { "email", "$email" },
                          { "location", "$location" },
                          { "countryId", "$countryId" },
                          { "_id", "$_id" }
                      } },
                    { "nReviews", new BsonDocument()
                      {
                          { "$sum", 1 }
                      } },
                    { "rating", new BsonDocument()
                      {
                          { "$avg", "$reviews.rating" }
                      } }
                })
                            .Lookup <BsonDocument, Country, BsonDocument>(countries, x => x["_id.countryId"], x => x.Id, z => z["country"])
                            .Unwind(x => x["country"])
                            .Project(new BsonDocument()
                {
                    { "_id", "$_id._id" },
                    { "nReviews", "$nReviews" },
                    { "rating", "$rating" },
                    { "name", "$_id.name" },
                    { "description", "$_id.description" },
                    { "type", "$_id.type" },
                    { "gallery", "$_id.gallery" },
                    { "website", "$_id.website" },
                    { "email", "$_id.email" },
                    { "address", "$_id.address" },
                    { "location", "$_id.location" },
                    { "openingHours", "$_id.openingHours" },
                    { "tags", "$_id.tags" },
                    { "phoneNumber", "$_id.phoneNumber" },
                    { "country", "$country" }
                }).As <ReadPlace>()
                            .FirstAsync();

                place.Distance = GeoHelper.CalculateDistance(new Location(latitude, longitude), new Location(place.Location.Location[1], place.Location.Location[0]));
                return(Json(place.ToJson(jsonWriterSettings)));
            }
            catch (Exception ex)
            {
                return(Json(ex.RaiseException()));
            }
        }