百度地图BD09坐标---->中国正常GCJ02坐标
/**
* 百度地图BD09坐标---->中国正常GCJ02坐标
* 腾讯地图用的也是GCJ02坐标
* @param double $lat 纬度
* @param double $lng 经度
* @return array();
*/
function Convert_BD09_To_GCJ02(lat,lng){
x_pi = 3.14159265358979324 * 3000.0 / 180.0;
x = lng - 0.0065;
y = lat - 0.006;
z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
lng = z * Math.cos(theta);
lat = z * Math.sin(theta);
var position = new Array();
position.push(lat);
position.push(lng);
return position;
}
地理位置两点距离的处理:
function GetDistance(lat1, lng1, lat2, lng2){
var radLat1 = Rad(lat1);
var radLat2 = Rad(lat2);
var a = radLat1 - radLat2;
var b = Rad(lng1) - Rad(lng2);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2)+Math.cos(radLat1)*Math.cos(radLat2)*Math.pow( Math.sin(b/2),2)));
s = s * 6378.137 ;// EARTH_RADIUS;
s = Math.round(s * 10000) / 10000; //输出为公里
//s=s.toFixed(4);
return s;
}