我正在使用自己编写的 Java 程序作为名为 Firebase 的休息平台的客户端。
我还有一个 Android 应用,用于从 Firebase 平台读取坐标,以更新 Google map 上的标记。
所以我的问题是,如果我有A点和B点的纬度和经度,我如何计算这两点之间的坐标?
想象一下这个案例场景
- A 点(左)纬度:39.091868 经度:-9.263187
- B点(右) 纬度:39.089815 长:-9.261857
例如,我如何计算这些点之间的 10 个坐标?
最佳答案
如果我理解正确,您需要中点(正好位于直线上两个位置的中间)。
这个网页对于所有这些事情都非常有帮助。 http://www.movable-type.co.uk/scripts/latlong.html
在 Android 中,它看起来像这样:
public LatLng midPoint(LatLng A, LatLng B) {
double phi1 = Math.toRadians(A.latitude);
double gamma1 = Math.toRadians(A.longitude);
double phi2 = Math.toRadians(B.latitude);
double deltaGamma = Math.toRadians(B.longitude - A.longitude);
double aux1 = Math.cos(phi2) * Math.cos(deltaGamma);
double aux2 = Math.cos(phi2) * Math.sin(deltaGamma);
double x = Math.sqrt((Math.cos(phi1) + aux1) * (Math.cos(phi1) + aux1) + aux2 * aux2);
double y = Math.sin(phi1) + Math.sin(phi2);
double phi3 = Math.atan2(y, x);
double gamma3 = gamma1 + Math.atan2(aux2, Math.cos(phi1) + aux1);
// normalise to −180..+180°
return new LatLng(Math.toDegrees(phi3), (Math.toDegrees(gamma3) + 540) % 360 - 180);
}
关于java - 获取两点之间的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39214370/