google maps middle of a polyline (centroid?)

后端 未结 5 894
情深已故
情深已故 2021-01-14 19:07

I have a list of polylines, just like google maps does when I click on the polyline I want an infowindow to show up just where I clicked, and it works just fine with this fu

5条回答
  •  伪装坚强ぢ
    2021-01-14 19:33

    So firstly you need to use the geometry library which calculates distances. Add libraries=geometry to your JS call, e.g.

    
    

    Assuming you know the start point and end point for your polyline, you should be able to do this:

    var inBetween = google.maps.geometry.spherical.interpolate(startLatlng, endLatlng, 0.5);  
    infowindow.position = inBetween;
    

    I guess if you don't already know the start and end points, you could work it out from polyline.getPath().

提交回复
热议问题