Google maps api 3 多边形路径中的标记

Google maps api 3 多边形路径中的标记,google-maps-api-3,Google Maps Api 3,通过扩展getBounds方法,我成功地将标记置于多边形路径的中心: //polyline google.maps.Polyline.prototype.getBounds = function() { var bounds = new google.maps.LatLngBounds(); this.getPath().forEach(function(e) { bounds.extend(e); }); return bounds; }; 我

通过扩展
getBounds
方法,我成功地将标记置于多边形路径的中心:

//polyline
google.maps.Polyline.prototype.getBounds = function() {
    var bounds = new google.maps.LatLngBounds();
    this.getPath().forEach(function(e) {
        bounds.extend(e);
    });
    return bounds;
};
我所要做的就是:

var marker = new google.maps.Marker({
    map: map,
    position: flight_path.getBounds().getCenter()
});
现在我希望标记位于路径的10%、25%或95%。
我如何才能做到这一点?

您可以使用来解决这个问题。将
libraries=geometry
添加到Google Maps JS URL

然后使用插值函数计算沿多段线放置标记的百分比

var inBetween = google.maps.geometry.spherical.interpolate(startLatlng, endLatLng, 0.5);  // 50%

这在一条多段线上很简单,但如果有多条线形成一条路径,可能会有点麻烦!然后你可以使用computeLength来计算总路径长度,自己计算95%的位置,然后我不确定…

是的,事实上,因为它使用的是.sphereal。类,它是为测地线设计的。我加载一个Kmlayer,其中包含从步行方向获取的路径,我希望在特定点上放置标记(例如英里标记)。这对我的目的有用吗?我不明白为什么不行(尽管我自己还没有使用KML层)