private static float DistanceTo(TreeBehavior thisTree, TreeBehavior thatTree) { if (thisTree.Equals(thatTree)) { return(float.MaxValue); } return(LocationUtil.GetDistance(thatTree.transform.position, thisTree.transform.position)); }
/// <summary> /// 获取最短距离的分店 /// </summary> /// <param name="session"></param> /// <param name="loc">地址</param> /// <param name="maxDist">最长距离</param> /// <returns></returns> public static Department GetMinDistDept(ISession session, TbLocation loc, double maxDist) { Department retVal = null; double minDest = double.MaxValue; string addrCode = loc.AddrCode; string paddrCode = ""; //如果达到街道级别 if (addrCode.Length >= 9) { //获取上级地址码 paddrCode = addrCode.Substring(0, 6); } else { //获取当级地址码 paddrCode = addrCode; } ICriteria criteria = session.CreateCriteria(typeof(Department)); //模糊查找当前代码 ICriterion criterion = Restrictions.Or( Restrictions.Eq("AddrCode", addrCode), Restrictions.Like("AddrCode", paddrCode + "%") ); criteria.Add(criterion); criterion = Restrictions.Eq("Del", false); criteria.Add(criterion); criteria.AddOrder(Order.Desc("AddrCode")); criteria.SetCacheable(true); IList <Department> depts = criteria.List <Department>(); foreach (Department dept in depts) { //如果地址相同则返回该商店 if (dept.Lat == loc.Lat && dept.Lng == loc.Lng) { retVal = dept; break; } else { //计算距离 double dest = LocationUtil.GetDistance(dept.Lat, dept.Lng, loc.Lat, loc.Lng); //取最短距离的分店 if (dest <= maxDist && dest < minDest) { minDest = dest; retVal = dept; } } } return(retVal); }