业务背景
物流同城配送,在用户下单的时候会进行配送超区校验,前端会将用户的定位传入后台服务,后台服务针对商家的自定义配送区域(通过地图控件拖拽出来的不规则图形)进行校验。
实现方案
利用java se工具类来做 java.awt.Polygon
使用到的api主要有:
public Polygon(int[] xpoints,int[] ypoints,int npoints)
Parameters:
xpoints - an array of X coordinates 所有点的x坐标
ypoints - an array of Y coordinates 所有点的y坐标
npoints - the total number of points in the Polygon 总共的点数
scene:
把商家通过地图拖拽的多边形各点传入进来,实例化Polygon对象
public boolean contains(double x,double y)
Parameters:
x - the specified X coordinate to be tested x坐标
y - the specified Y coordinate to be tested y坐标
scene:
获取用户当前定位的经纬度,作为x,y坐标系传入进行判断
使用示例
判断规则矩形包含点