latLng from polyLine Percentage

前端 未结 1 1447
[愿得一人]
[愿得一人] 2020-12-06 15:06

How do I return a latLng value from a given percentage along a polyLine? I have spent a day on this using interpolate and individual nodes. Is their an easier function out t

相关标签:
1条回答
  • 2020-12-06 15:34

    http://www.geocodezip.com/scripts/v3_epoly.js

    written for the Google Maps Javascript API v2 ported to v3. Documentation for the v2 version

    Has these two methods:

    • .Distance() returns the length of the poly path
    • .GetPointAtDistance() returns a GLatLng at the specified distance
      along the path.
      The distance is specified in metres
      Returns null if the path is shorter than that

    This should work (if you include that script and your polyline variable is "polyline"):

    var latlng = polyline.GetPointAtDistance(polyline.Distance()*(desired percentage)/100);
    

    of course if you polyline isn't changing in length, it would be more efficient to compute the length once an use it each time you want to find a point on the polyline.

    var polylength = polyline.Distance();
    var latlng = polylength*(desired percentage)/100);
    
    0 讨论(0)
提交回复
热议问题