2

I have already the conversion of latitude and longitude coordinates (current) to pixel coordinates. Then I also successfully plotted the current into still image. But the problem is the still image angle is not proportionate to real world map.

Here's the lat & long to pixel convertsion (Thanks to @Dan S , answered here 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;
}

Here's the output of a given lat long against my still image (actual output of the green mark):

enter image description here

Here's the real world map of a given lat long (expected output of the green mark): enter image description here

Community
  • 1
  • 1
eros
  • 4,946
  • 18
  • 53
  • 78
  • for sure, i am not the only one wants this post. if you have any idea, please share with us. – eros Sep 13 '11 at 10:21

0 Answers0