我有一个区域的中心点坐标(lng,lat),我想为此区域计算围绕该中心点的边界框中四个角的坐标(lng,lat).从中心到每个角的距离为10米.
插图:
如何在Javascript中执行此操作?
是否有一个用于此类事情的图书馆,还是我必须舍弃多年来无视Allard夫人的三角学课的大脑部分?
解决方法:
根据Bruno Pinto给出的答案here
我最终创建并使用了它:
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;
}
}