我正在尝试使用一部分代码(类似于我下面的代码),因此OBJECT_LOC和CONVERTED_LOC完全相同。我认为代码对于我正在做的事情非常简单,但由于某种原因它们并不平等?我究竟做错了什么? (您可以在下面看到输出)。
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.Length;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// 45:20:00.0N/24:00:00.0E
LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false,
24, 00, 00.0f).getLatLonPoint();
System.out.println("BASE_LOC: " + BASE_LOC);
LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.346556);
System.out.println("OBJECT_LOC: " + OBJECT_LOC);
float distanceX = BASE_LOC.distance(new LatLonPoint(BASE_LOC
.getLatitude(), OBJECT_LOC.getLongitude()));
float distanceY = BASE_LOC.distance(new LatLonPoint(OBJECT_LOC
.getLatitude(), BASE_LOC.getLongitude()));
LatLonPoint CONVERTED_POINT = new LatLonPoint(BASE_LOC.getLatitude()
+ Length.DECIMAL_DEGREE.fromRadians(distanceY),
BASE_LOC.getLongitude()
+ Length.DECIMAL_DEGREE.fromRadians(distanceX));
System.out.println("CONVERTED_POINT " + CONVERTED_POINT);
}
}
输出:
BASE_LOC: LatLonPoint[lat=45.333332,lon=24.0]
OBJECT_LOC: LatLonPoint[lat=52.749355,lon=26.346556]
CONVERTED_POINT LatLonPoint[lat=52.749355,lon=25.649527]
答案 0 :(得分:1)
在查看API文档和一些关于地理的文献之后,看起来你发现第二点的方法是有缺陷的。正确的方法是使用距离和方位(方位角)。以下是更正后的代码:
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;
public class TestProgram {
/**
* @param args
*/
public static void main(String[] args) {
// 45:20:00.0N/24:00:00.0E
LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false, 24, 00, 00.0f).getLatLonPoint();
System.out.println("BASE_LOC: " + BASE_LOC);
LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.0);
System.out.println("OBJECT_LOC: " + OBJECT_LOC);
float distance = BASE_LOC.distance(OBJECT_LOC);
float az = BASE_LOC.azimuth(OBJECT_LOC);
LatLonPoint CONVERTED_POINT = BASE_LOC.getPoint(distance, az);
System.out.println("CONVERTED_POINT " + CONVERTED_POINT);
}
}
此处提供了一些信息 - http://www.movable-type.co.uk/scripts/latlong.html
答案 1 :(得分:0)
当你正在进行BASE_LOC.distance()调用时,你需要在两个距离的参数中交换OBJECT_LOC / BASE_LOC。 OBJECT_LOC / BASE_LOC在一个,BASE_LOC / OBJECT_LOC在另一个。