我有一张地图,我在上面画了一个多边形。绘制初始多边形后,我将地图旋转一圈,每次1度,在大约5秒钟内完成一个完整的圆圈。
问题是我希望多边形保持在屏幕上的相同位置,而不是在地图上。如果在旋转地图时我对多边形不执行任何操作,则多边形也会旋转。这不是理想的行为,我希望多边形在旋转地图时保持在屏幕上的相同位置。
我尝试使用以下方法来获取新的多点但是它没有正确出现。我一直使用0和135轴承作为我的测试,结果如下所示。
方法:
//degrees = counter-clockwise from north
private List<LatLng> getPolygonPoints(LatLng startPoint, int bearing) {
LatLng firstPoint = getPolyPoint(startPoint, 100, getPolyPointDifference(90, bearing));
LatLng fourthPoint = getPolyPoint(startPoint, 100, getPolyPointDifference(270, bearing));
LatLng secondPoint = getPolyPoint(firstPoint, 300, getPolyPointDifference(10, bearing));
LatLng thirdPoint = getPolyPoint(fourthPoint, 300, getPolyPointDifference(350, bearing));
return Arrays.asList(
startPoint,
firstPoint,
secondPoint,
thirdPoint,
fourthPoint,
startPoint
);
}
private int getPolyPointDifference(int fromNorth, int bearing) {
int[] compass = new int[360];
int currentBearing = 360 - bearing;
if (currentBearing == 360) {
currentBearing = 0;
}
for (int i = 0; i < 360; i++) {
compass[i] = currentBearing;
currentBearing++;
if (currentBearing >= 360) {
currentBearing = 0;
}
}
Log.i(LOG_TAG, "fromNorth: "+fromNorth+" return: "+compass[fromNorth]);
return compass[fromNorth];
}
//distance = meters
//degrees = counter-clockwise from north
private LatLng getPolyPoint(LatLng fromLocation, int distance, int degrees) {
double radians = (degrees * Math.PI) / 180;
double distanceX = distance * Math.sin(radians);
double distanceY = distance * Math.cos(radians);
double deltaLatitude = distanceY / 110540;
double deltaLongitude = distanceX / (111320 * Math.cos(fromLocation.latitude));
double pointLatitude = fromLocation.latitude + deltaLatitude;
double pointLongitude = fromLocation.longitude + deltaLongitude;
return new LatLng(pointLatitude, pointLongitude);
}
输出:
轴承= 0
方位= 135
结果:
答案 0 :(得分:0)
问题是我希望多边形保持在屏幕上的相同位置,而不是地图上。
然后不要在地图上绘制它,而是在你创建的覆盖表面上绘制。