Пример #1
0
        private StoreSDTO MongoToDto2(GeoNearResult <StoreMgDTO> .GeoNearHit storeMgHit)
        {
            StoreSDTO store = MongoToDto(storeMgHit.Document);

            store.Distance = (decimal)storeMgHit.Distance * 100000;
            return(store);
        }
Пример #2
0
        /// <summary>
        ///  获取门店列表(按用户当前位置到门店的距离排序)
        /// <para>Service Url: http://testbtp.iuoooo.com/Jinher.AMP.BTP.SV.StoreSV.svc/GetStoreByLocation
        /// </para>
        /// </summary>
        /// <param name="slp">参数实体类</param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.NStoreSDTO GetStoreByLocationExt(StoreLocationParam slp)
        {
            if (slp == null)
            {
                return(null);
            }
            else if (slp.AppId == Guid.Empty)
            {
                return(null);
            }
            else if (slp.Longitude > 180 || slp.Longitude < -180)
            {
                return(null);
            }
            else if (slp.Latitude > 90 || slp.Latitude < -90)
            {
                return(null);
            }

            if (slp.CurrentPageIndex < 1)
            {
                slp.CurrentPageIndex = 1;
            }
            if (slp.PageSize <= 0)
            {
                slp.PageSize = 20;
            }

            //GeoNearOptions.SetSpherical
            var queryList = new List <IMongoQuery>();

            queryList.Add(Query <StoreMgDTO> .Where(c => c.AppId == slp.AppId));

            GeoNearResult <StoreMgDTO> ss = MongoCollections.Store.GeoNear(Query.And(queryList), (double)slp.Longitude, (double)slp.Latitude, int.MaxValue);
            var storeMgs = ss.Hits.Skip((slp.CurrentPageIndex - 1) * slp.PageSize).Take(slp.PageSize).ToList();

            NStoreSDTO nsr = new NStoreSDTO();

            if (storeMgs.Any())
            {
                List <StoreSDTO> srList     = storeMgs.ConvertAll <StoreSDTO>(MongoToDto2);
                List <string>    proviences = srList.Select(s => s.Province).Distinct().ToList();
                nsr.Proviences = proviences;
                nsr.Stroes     = srList;
            }
            return(nsr);
        }
        public IEnumerable <PlaygroundEntity> GetByLocation(float lat, float lng)
        {
            var earthRadius = 6378.0; // km
            var rangeInKm   = 10.0;   // km

            GetCollection().EnsureIndex(IndexKeys.GeoSpatial("Loc"));

            //var near =
            //    Query.GT("ExpiresOn", now);

            var options = GeoNearOptions
                          .SetMaxDistance(rangeInKm / earthRadius /* to radians */)
                          .SetSpherical(true);

            GeoNearResult <PlaygroundEntity> results = GetCollection().GeoNear(
                Query.Null,
                lng, // note the order
                lat, // [lng, lat]
                200,
                options
                );

            return(results.Hits.Select(result => result.Document));
        }