Jquery/JavaScript公式,添加x米/英里/公里到latlng坐标

Jquery/JavaScript Formula that adds x meters/miles/km to latlng coordinates

本文关键字:latlng 坐标 英里 公式 JavaScript 添加 Jquery      更新时间:2023-09-26

我正在寻找一个公式在jquery/javascript,我可以用它来获得新的坐标,如果我有一个现有的长坐标。我在谷歌地图上有几个标记,我想把它们分散到一个均匀的距离。

我所有的标记都有相同的长坐标。我正在查看Haversine公式,但是我没有看到任何公式可以从现有的对长坐标中给我新的坐标。

在一些关于

的研究中发现
http://www.movable-type.co.uk/scripts/latlong.html
/**
 * Returns the destination point from this point having travelled the given distance (in km) on the 
 * given initial bearing (bearing may vary before destination is reached)
 *
 *   see http://williams.best.vwh.net/avform.htm#LL
 *
 * @param   {Number} brng: Initial bearing in degrees
 * @param   {Number} dist: Distance in km
 * @returns {LatLon} Destination point
 */
LatLon.prototype.destinationPoint = function(brng, dist) {
  dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN;
  dist = dist/this._radius;  // convert dist to angular distance in radians
  brng = brng.toRad();  // 
  var lat1 = this._lat.toRad(), lon1 = this._lon.toRad();
  var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + 
                        Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );
  var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), 
                               Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));
  lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI;  // normalise to -180..+180º
  return new LatLon(lat2.toDeg(), lon2.toDeg());
}