我有一个将纬度和经度转换为localCordinateSystem的功能
const EARTH_RADIUS_KM = 6371.0;
const distanceInMeters = (lat1, lon1, lat2, lon2) => {
const lonDiff = toRadians(lon2 - lon1);
const latDiff = toRadians(lat2 - lat1);
const a = Math.pow(Math.sin(latDiff / 2), 2) + Math.cos(toRadians(lat1)) *
Math.cos(toRadians(lat2)) * Math.pow(Math.sin(lonDiff / 2), 2);
const angle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return angle * EARTH_RADIUS_KM * 1000.0;
};
const localCoordinateSystem = (lat, lon, originLat, originLon, radius) => {
let latDist = distanceInMeters(originLat, originLon, lat, originLon);
let lonDist = distanceInMeters(originLat, originLon, originLat, lon);
if (lat < originLat) latDist *= -1;
if (lon < originLon) lonDist *= -1;
return {
x: parseFloat(latDist) + parseFloat(radius),
y: parseFloat(lonDist) + parseFloat(radius),
};
};
如果您看到函数localCoordinateSystem接受lat,lon,originLat,originLon和radius并返回x和y。
但是现在我想要一个具有x,y,originLat,originLon和radius并返回lat和lon的函数。