作业帮 > 数学 > 作业

怎样算经纬度

来源:学生作业帮 编辑:作业帮 分类:数学作业 时间:2022/08/14 14:44:09
怎样算经纬度
//根据经纬度坐标算两点间距离,通用算法,忽略80或54坐标系问题,有误差
// 两点间的距离,单位为米
//javascript编写,可以按需要用其他编程语言转换.
function calcDistance(mX,mY,mX2,mY2) {
var mDistance = 0;
var Lon1 = mX2 * Math.PI / 180;
var Lon2 = mX * Math.PI / 180;
var Lat1 = mY2 * Math.PI / 180;
var Lat2 = mY * Math.PI / 180;
var LonDist = Lon1-Lon2;
var LatDist = Lat1-Lat2;
var xD = Math.abs(mX - mX2);
var yD = Math.abs(mY - mY2);
mDistance = Math.sqrt(Math.pow(xD,2) + Math.pow(yD,2));
var theDist = convertUnits(mDistance);
var u = Math.pow(10,numDecimals);
currentMeasure = parseInt(theDist*u+(5/10))/u;
return currentMeasure;
}
// convert the amounts to new units
function convertUnits(theDist1) {
var theDist = parseFloat(theDist1);
var mDistance = theDist;
mDistance = theDist * (6213711922/10000000000000);
var u = Math.pow(10,numDecimals);
mDistance = parseInt(mDistance * u + (5/10)) / u
return mDistance;