-1
我有一个地图,我绘制了一个多边形。绘制完初始多边形后,我将地图旋转一圈,每次旋转1度,大约5秒钟完成一个完整的圆。Android旋转地图,但在同一屏幕位置保留多边形
事情是,我希望多边形保持在屏幕上的相同位置,而不是在地图上。如果我在旋转地图时对多边形不做任何处理,多边形也会旋转。这不是所需的行为,我希望多边形在旋转地图时保留在屏幕上的相同位置。
我已经尝试使用以下方法来获得新的多点,但它不是正确出来。我一直在使用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
- fromNorth:90返回:90
- fromNorth:270返回:270
- fromNorth:10返回:10
- fromNorth:350返回:350
轴承= 135
- fromNorth:90返回:315
- fromNorth:270返回:135
- fromNorth :10回报:235
- from north:350 return:215
结果:
问题是我只显示属于这个多边形的地图标记,所以多边形本身必须是地图的一部分,以知道它在地图上的坐标 – shiznatix 2014-11-06 10:51:07