从另一个GPS位置+距离计算位置



开发Javascript应用程序,我正在寻找一种方法来计算目标点的GPS坐标,来自另一个位置(纬度|经度(+一定距离(例如,再往南20公里(。为了表达这个问题,人们可以说:我当前位置加上南北 20 公里的 GPS 坐标是多少?

伪公式:

目标位置 = 已知位置 + 距离

哪里:

  • 目标位置由 (纬度|经度(
  • 已知位置由 (纬度|经度(
  • 距离是更北或更南的直线矢量

对福穆拉有什么想法吗?

一旦我们知道以公里为单位的经向距离,并且知道这是 360° 纬度,我们就可以计算由于向北或向南移动 x 公里而导致的偏移量。

我们向北或向南移动的每一度,我们都会移动 (40007.86/360( = 111.13 公里。

此外,我们还将包括一些针对极点附近位置的错误检查。

我将添加一个更通用的公式,用于在给定北部和东部偏移量的情况下获取新位置。(按照通常的惯例,南部和西部为负数(,这仅适用于小位移。

function getNewLatitude(latitude, distanceKm) {
const meridionalRadiuskm = 40007.86;
latitude = (latitude + distanceKm / (meridionalRadiuskm / 360));
if (latitude > 90) return 180 - latitude;
if (latitude < -90) return -(180 + latitude);
return latitude;
}
console.log(getNewLatitude(50, 100));
console.log(getNewLatitude(50, -100));
// This function may also be useful, you can use this to get a new location base on a north/south / east/west offset in km. Note that accuracy will start to reduce as the offset increases. 
function getNewLocation(lat, lon, offsetNorthKm, offsetEastKm) {
// The approximate distance in kilometres of one degree at 0,0.
const ONE_DEGREE_KM = 111.32;
const deltaLatitude = offsetNorthKm / ONE_DEGREE_KM;
const deltaLongitude = offsetEastKm / (ONE_DEGREE_KM * Math.cos(Math.PI * lat / 180));
let result = { 
lat:  lat + deltaLatitude,
lon:  lon + deltaLongitude
}
return result;
}

您可以使用Geolib库,它将为您提供更精确的结果,尤其是在极点附近。

示例:这将计算 15000 米,从提供的经度/经度偏移量 180 度(南(。

geolib.computeDestinationPoint(
{ latitude: 52.518611, longitude: 13.408056 },
15000,
180
);

请注意,方向以度为单位(0 = 360 = 北,180 = 南等(。使用此库还可以执行其他有趣的计算,例如:

  • 获取 2 点之间的距离
  • 获取点数组的中心
  • 获取指南针方向
  • 查找最近的点
  • 等等

最新更新