|
Model.prototype.setdkq = function(event) {
var EARTH_RADIUS = 6378137.0; //单位M
var PI = Math.PI;
function getRad(d){
return d*PI/180.0;
}
function success(data){
// alert(data.coords.longitude);
//alert(data.coords.latitude);
// var pointA = new BMap.Point(103.775327,29.583115);
// 公司地址坐标A
// alert(data.coords.latitude);
alert(jsgetjl(103.775025,29.583264,data.coords.longitude,data.coords.latitude));
}
function fail(msg){
$(self.getElementByXid('label1')).text("错误消息:"+msg);
}
function jsgetjl(lat1, lng1, lat2, lng2) {//计算距离
var radLat1 = getRad(lat1);
var radLat2 = getRad(lat2);
var a = radLat1 - radLat2;
var b = getRad(lng1) - getRad(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*EARTH_RADIUS;
s = Math.round(s*10000)/10000.0;
return s;
}
navigator.geolocation.getCurrentPosition(success, fail, null);
}; |
|