Javascript - 计算中心点周围四个角的地理坐标点

Zig*_*rth 4 javascript geometry trigonometry geolocation node.js

我有一个区域的中心点坐标 (lng, lat),我想计算围绕该中心点的边界框中四个角的坐标 (lng, lat)。从中心到每个角落的距离是 10 米。

插图:

在此处输入图片说明

我如何在 Javascript 中做到这一点?

有这样的图书馆吗,还是我必须清除掉多年来无视阿拉德夫人三角学课的大脑部分?

Zig*_*rth 5

根据 Bruno Pinto在这里给出的答案, 我最终创建并使用了它:

function getBoundingBox(pLatitude, pLongitude, pDistanceInMeters) {


            var latRadian = pLatitude.toRad();

            var degLatKm = 110.574235;
            var degLongKm = 110.572833 * Math.cos(latRadian);
            var deltaLat = pDistanceInMeters / 1000.0 / degLatKm;
            var deltaLong = pDistanceInMeters / 1000.0 / degLongKm;


            var topLat = pLatitude + deltaLat;
            var bottomLat = pLatitude - deltaLat;
            var leftLng = pLongitude - deltaLong;
            var rightLng = pLongitude + deltaLong;

            var northWestCoords = topLat + ',' + leftLng;
            var northEastCoords = topLat + ',' + rightLng;
            var southWestCoords = bottomLat + ',' + leftLng;
            var southEastCoords = bottomLat + ',' + rightLng;

            var boundingBox = [northWestCoords, northEastCoords, southWestCoords, southEastCoords];


            return boundingBox;
}

if (typeof(Number.prototype.toRad) === "undefined") {
  Number.prototype.toRad = function() {
  return this * Math.PI / 180;
 }
}
Run Code Online (Sandbox Code Playgroud)


Aya*_*yan 0

您可以看一下以下功能:-

/*The getRectCoordinates takes the coordinates of the center point 
and the radial distance at which you want to find the coordinates*/
function getRectCoordinates (x,y,r) {
	//theta is the angle hard-coded to 45 degrees to think as the square 
	var theta = Math.PI/4,
	cos = Math.cos,
	sin = Math.sin;
	return {
		'topRight' : {
			'x' : x + r*cos(theta),
			'y' : y + r*sin(theta)
		},
		'bottomRight' : {
			'x' : x + r*cos(theta),
			'y' : y - r*sin(theta)
		},
		'topLeft' : {
			'x' : x - r*cos(theta),
			'y' : y + r*sin(theta)
		},
		'bottomLeft' : {
			'x' : x + r*cos(theta),
			'y' : y - r*sin(theta)
		}
	}
}

//An example for this (Check console for output): 
console.log(getRectCoordinates(2,3,10));
Run Code Online (Sandbox Code Playgroud)

兄弟你的问题解决了的话请告诉我。