1

我有一些商场的图像,我需要将它们用作我正在制作的应用程序的地图。我有地图底角的 GPS 纬度/经度,我计算出从底部 GPS 坐标到地图图像顶部的距离。但是这些不是直线上下的线性地图,这意味着我不能只绘制我的纬度和经度都很好而且整洁。

我尝试过使用各种公式,而且我非常接近,但我无法绘制地图左上角和右上角的顶部纬度和经度。到目前为止,这就是我所拥有的:

double distanceFromLeftToRightGPS = bottomLeft.distanceTo(bottomRight);
double bearingleftToRight= bottomLeft.bearingTo(bottomRight);

double distmapFromLeftToRightImg = map.getWidth();
double distmapFromTopToBottomImg = map.getHeight();

double percentageValueOfTopToBottomImg = (distmapFromTopToBottomImg * 100)
        / distmapFromLeftToRightImg;
double distanceFromTopToBottomGPS = (percentageValueOfTopToBottomImg * 0.01)
        * distanceFromLeftToRightGPS;

double bearingToTopFromBottom = -90;
double lat1 = Math.toRadians(bottomLeft.getLatitude());
double lon1 = Math.toRadians(bottomLeft.getLongitude());

double dist = (distanceFromTopToBottomGPS/1000f)/6371.0f;

double lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist)
        + Math.cos(lat1) * Math.sin(dist) * Math.cos(bearingToTopFromBottom));

double a = Math.atan2(Math.sin(bearingToTopFromBottom) * Math.sin(dist)
        * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));

System.out.println("a = " +  a);
double lon2 = lon1 + a;

lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;

System.out.println("Latitude = " + Math.toDegrees(lat2) + "\nLongitude = "
        + Math.toDegrees(lon2));

这让我非常接近,但最终位置偏离了它真正应该在的位置。我也不确定应该使用什么方位来查看地图底部的内容。如果其他人有一些关于如何让它工作的信息,那就太棒了。

4

2 回答 2

1

您需要用它们的纬度/经度坐标来识别地图上的 3 个点。然后使用Helmert变换。
这里有一些关于“Helmert”转换的帖子。

于 2013-03-14T11:43:47.803 回答
1

这两种方法是我从 SO 上的其他一些帖子中提出的解决方案。如果您的地图左上角和右下角有左上角 GPS 坐标和右下角 GPS 坐标,那么使用这两种方法,您可以找出在地图上绘制第三个 GPS 坐标的位置。这些将与您的左上角和右下角 GPS 坐标一样准确。然后我使用画布在位图上绘制第三个点。

public final static double OneEightyDeg = 180.0d;
public static double ImageSizeW, ImageSizeH ;

getSizesFromBitmap(ImageSizeW, ImageSizeH);


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 * ImageSizeH;

    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 * ImageSizeW;

    return currentPixelX;
}
于 2013-03-14T17:28:26.977 回答