Beispiel #1
0
        public async Task <List <Lugar> > GetNearLugaresTo(LugarPost model)
        {
            var   geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            Point coord           = geometryFactory.CreatePoint(new Coordinate(model.Latitude, model.Longitude));

            var result = await _context.Lugares
                         .OrderBy(l => l.Location.Distance(coord))
                         .Where(l => l.Location.IsWithinDistance(coord, 0.005))  // 0.005 --> 5cuadras
                         .ToListAsync();

            return(result);
        }
Beispiel #2
0
        public async Task <Lugar> AddLugar(LugarPost model)
        {
            var   geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            Lugar newLugar        = _mapper.Map <LugarPost, Lugar>(model);

            newLugar.Location = geometryFactory.CreatePoint(new Coordinate(model.Latitude, model.Longitude));

            await _context.Lugares.AddAsync(newLugar);

            await _context.SaveChangesAsync();

            return(newLugar);
        }
Beispiel #3
0
        public async Task <IActionResult> GetLugaresCercanos([FromBody] LugarPost model)
        {
            List <Lugar> lugares = new List <Lugar>();

            lugares = await _service.GetNearLugaresTo(model);

            List <LugarPost> returnList = new List <LugarPost>();

            foreach (Lugar lu in lugares)
            {
                returnList.Add(new LugarPost {
                    Direccion = lu.Direccion,
                    Latitude  = lu.Location.Coordinate.X,
                    Longitude = lu.Location.Coordinate.Y
                });
            }
            return(Ok(new OkApiResponse(returnList)));
        }