我已经将纬度和经度坐标(当前)转换为像素坐标。然后我也成功地将电流绘制成静止图像。但问题是静止图像角度与现实世界地图不成比例。
这是lat&长到像素的转换(感谢@Dan S,在这里回答mark a given lat long into still image):
public final static BigDecimal PI = BigDecimal.valueOf(Math.PI);
public final static double OneEightyDeg = 180.0d;
public final static double ImageSize = 512d;
public double getCurrentPixelY(Location upperLeft, Location lowerRight, Location current) {
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceY = Math.cos(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceY = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelY = currentDistanceY / totalDistanceY * ImageSize;
return currentPixelY;
}
public double getCurrentPixelX(Location upperLeft, Location lowerRight, Location current) {
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.sin(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.sin(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelX = currentDistanceX / totalDistanceX * ImageSize;
return currentPixelX;
}
这是我的静止图像(绿色标记的实际输出)给定纬度的输出:
这是给定lat long的真实世界地图(绿色标记的预期输出):