1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| public class GpsUtil {
public static int getDistance(double longitudeStart, double latitudeStart, double longitudeEnd, double latitudeEnd) { double radLatStart = Math.toRadians(latitudeStart); double radLatEnd = Math.toRadians(latitudeEnd); double radLat = radLatStart - radLatEnd; double radLonDiff = Math.toRadians(longitudeStart) - Math.toRadians(longitudeEnd); double sum = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(radLat / 2), 2) + Math.cos(radLatStart) * Math.cos(radLatEnd) * Math.pow(Math.sin(radLonDiff / 2), 2))); sum = sum * 6378137.0; return (int) Math.round(sum); }
public static boolean isInArea(double longitude, double latitude, List<Point2D.Double> pointList) { Point2D.Double point = new Point2D.Double(longitude, latitude);
GeneralPath peneralPath = new GeneralPath();
Point2D.Double firstPoint = pointList.get(0);
peneralPath.moveTo(firstPoint.x, firstPoint.y); pointList.remove(0);
for (Point2D.Double aDouble : pointList) { peneralPath.lineTo(aDouble.x, aDouble.y); } peneralPath.lineTo(firstPoint.x, firstPoint.y); peneralPath.closePath(); return peneralPath.contains(point); } }
|