通过经纬度计算距离(flex,actionscript)

public class LatLngUtil
{
public static const EARTH_RADIUS:Number = 6378.137;
private static function rad(d:Number):Number
{
return d * Math.PI / 180.0;
}

/**
* 获取两个经纬度之前的距离,千米<br/>
* 纬度相差0.0009,距离就相差100米,经度相差0.00105,距离就相差100米,因此取近似值,都为0.001
*/
public static function GetDistance(lat1:Number, lng1:Number, lat2:Number, lng2:Number):Number
{
var radLat1:Number = rad(lat1);
var radLat2:Number = rad(lat2);
var a:Number = radLat1 - radLat2;
var b:Number = rad(lng1) - rad(lng2);
var s:Number= 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;
return s;
}


}

你可能感兴趣的:(function,Flex,Class,actionscript)