高德已知圆心,半径,计算圆弧坐标
程序员文章站
2022-05-21 09:28:53
...
public void addPolylinescircle(LatLng centerpoint, int radius) {
double r = 6371000.79;
PolylineOptions options = new PolylineOptions();
int numpoints = 360;
double phase = 2 * Math.PI / numpoints;
//画图
for (int i = 0; i < numpoints; i++) {
/**
* 计算坐标点
*/
double dx = (radius * Math.cos(i * phase));
double dy = (radius * Math.sin(i * phase));//乘以1.6 椭圆比例
/**
* 转换成经纬度
*/
double dlng = dx / (r * Math.cos(centerpoint.latitude * Math.PI / 180) * Math.PI / 180);
double dlat = dy / (r * Math.PI / 180);
double newlng = centerpoint.longitude + dlng;
options.add(new LatLng(centerpoint.latitude + dlat, newlng));
}
aMap.addPolyline(options.width(10).useGradient(true).setDottedLine(true));
}