如何绘制的图像上的GPS位置被用作地图?(How to plot a GPS location on

2019-08-17 14:26发布

我有商场的图片,我需要为一个应用程序,我制作地图使用。 我有GPS /纬地图的底角,我想通了距离底部GPS坐标,这将是地图图像的顶部。 如何以往这些都不是直上直下的线性图的意思我不能只画出我的纬度和长所有漂亮和整洁。

我一直在使用各种公式试过,我很接近,但我不能绘制顶部lat和长地图的左上角和右上角的。 到目前为止,这是我有:

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));

这让我哦,如此接近,但最终位置不在从它真的应该。 我也不能确定,我应该使用看看什么会从地图的底部了一下轴承。 如果任何人有关于如何得到这个工作,这将是真棒一些信息。

Answer 1:

你需要与他们的经/纬度坐标,在地图上找出3点。 然后使用Helmert变换。
这里的所以有一些职位“赫尔默特”转型。



Answer 2:

在解决方案,我想出了从这里SO一些其他职位这两种方法。 如果你有一个左上角坐标GPS和地图,然后使用这两种方法的左上角和右下角右下方GPS坐标,你可以计算出在哪里画你的第三个坐标GPS在地图上。 这些都将作为acurate的为您的左上方和右下方GPS COORDS是。 然后我画上用帆布位图中的第三点。

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;
}


文章来源: How to plot a GPS location on an image being used as a map?