计算openlayers两点之间的距离

distanceTo: function(point) {

    var distance = 0.0;

    if ((this.x != null) && (this.y != null) &&

    (point != null) && (point.x != null) && (point.y != null)) {

        var dx2 = Math.pow(this.x - point.x, 2);

        var dy2 = Math.pow(this.y - point.y, 2);

        distance = Math.sqrt(dx2 + dy2);

    }

    return distance;

}

返回的单位为 km

posted @ 2015-05-27 21:43  Liu66~  阅读(2989)  评论(0编辑  收藏  举报