javascript - 在 Google map 中编辑折线

标签 javascript jquery google-maps google-maps-api-3

我正在使用 Google Maps V3 API 创建一条包含 2 个点的多段线。现在我已经创建了多段线,我想缩短它。

问题:我需要折线从起点延伸到起点和终点之间的中点。我怎样才能做到这一点?

我能找到的最接近的函数是 computeDistanceBetween() 函数,用于查找 2 个 LatLng 点之间的距离。

Javascript 代码

    start_latlng = new google.maps.LatLng(42.354183,-71.065063);
    end_latlng = new google.maps.LatLng(42.354183,-71.069063);

    start_marker = new google.maps.Marker({
        position: start_latlng,
        map: map
    });
    end_marker = new google.maps.Marker({
        position: end_latlng,
        map: map
    });

    path = [];
    path.push(start_latlng);
    path.push(end_latlng);

    var polyline = new google.maps.Polyline ({
        strokeColor: "#970E04", 
        strokeOpacity: 1.0, 
        strokeWeight: 2, 
        path: path,
        map: map
    })

最佳答案

这是映射函数的重要资源:

http://www.movable-type.co.uk/scripts/latlong.html

有一个计算中点的例子。

关于javascript - 在 Google map 中编辑折线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8124488/

相关文章:

jquery - 防止 colorbox 实例关闭

javascript - Angular2 在创建 ngSwitch 新 View 后调用自定义函数

javascript - 将用户选择从一个 Canvas 复制到另一个 Canvas

javascript - JQuery Double Scroll - 边距/对齐问题

javascript - 使函数四舍五入到最近的刻钟

javascript - Google Map API v3 — 设置边界和中心

javascript - 使用 MarkerClustererPlus 和 OverlappingMarkerSpiderfier 重叠指针

Javascript Async=true 属性

javascript - Select2 在网站上无法正常工作

javascript - 使用 javascript 或 jquery 在一页上打印一行