**
判断一个点是否在一组经纬度包围圈内
**
将判断点经纬度塞入Point2D.Double中,将包围圈放入点集之中。
*
public static boolean isInPolygon(ArrayList<LatLng> bound, double pointlng, double pointLat)
{
Point2D.Double point = new Point2D.Double(pointlng, pointLat);
List<Point2D.Double> pointList = new ArrayList<Point2D.Double>();
for (int i = 0; i < bound.size(); i++) {
pointList.add(new Point2D.Double(bound.get(i).lng, bound.get(i).lat));
}
return check(point, pointList);
}
将点集中的数据组成不规则几何图形,使用封装好的方法判断点是否在几何图形内部。
public static boolean check(Point2D.Double _point, List<Point2D.Double> polygon)
{
java.awt.geom.GeneralPath peneralPath = new java.awt.geom.GeneralPath();
Point2D.Double first = polygon.get(0);
peneralPath.moveTo(first.x, first.y);
polygon.remove(0);
for(Point2D.Double d : polygon)
{
peneralPath.lineTo(d.x, d.y);
}
peneralPath.lineTo(first.x, first.y);
peneralPath.closePath();
return peneralPath.contains(_point);
}