1. function getDistance(lat1, lng1, lat2, lng2) {
    2. var dis = 0;
    3. var radLat1 = toRadians(lat1);
    4. var radLat2 = toRadians(lat2);
    5. var deltaLat = radLat1 - radLat2;
    6. var deltaLng = toRadians(lng1) - toRadians(lng2);
    7. var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
    8. return dis * 6378137;
    9. function toRadians(d) {
    10. return d * Math.PI / 180;
    11. }
    12. }

    返回的距离单位为米