class="java" name="code">/**** * 根据经纬度 获取数据 工具类 * @author xuli * */ public class LngLatDistanceUtils { private static final Logger log = LoggerFactory.getLogger(LngLatDistanceUtils.class); /*** * 经纬度计算距离 * @author xuli * * @param lat1 纬度1 * @param lng1 经度1 * @param lat2 纬度2 * @param lng2 经度2 */ public static Float getDistance(Double lat1, Double lng1, Double lat2, Double lng2){ double EARTH_RADIUS = 6378.137;// 地球半径 double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS; Float ss = (float) (Math.round(s * 1000))/1000; return ss; } private static double rad(Double d){ return d * Math.PI / 180.0; } /**** * 判断点是否在多边形内(不包含边界) * * @author wanwenjun * @param point 点 * @param polygon 多边形 * @return */ public static boolean checkWithJdkGeneralPath(Point2D.Double point, List<Point2D.Double> polygon) { java.awt.geom.GeneralPath p = new java.awt.geom.GeneralPath(); // 初始化起点坐标 Point2D.Double first = polygon.get(0); p.moveTo(first.x, first.y); for (Point2D.Double d : polygon) { // 遍历点,并按遍历的顺序画线 p.lineTo(d.x, d.y); } p.lineTo(first.x, first.y); p.closePath(); return p.contains(point); } }
?