How to plot a GPS location on an image being used as a map?

笑着哭i 提交于 2019-12-04 19:41:39

You need to identify 3 points on the map with their lat/lon coordinates. Then use the Helmert Transformation.
Here on SO there are some post for "Helmert" transformation.

These two methods where the solution I came up with from some other posts here on SO. If you have a top left GPS coord and a bottom right GPS coord for the top left and bottom right corners of your map then using these two methods you can figure out where to draw your third GPS coord on the map. These will be as acurate as your top left and bottom right GPS coords are. I then draw the third point on the bitmap using a canvas.

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!