本文介绍了latLng来自polyLine百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从polyLine的给定百分比返回latLng值?
我使用插值和单个节点花了一天的时间。 Google地图API v3
谢谢!

解决方案



为Google Maps Javascript API v2移植到v3而编写。



有以下两种方法:


  • .Distance()返回多路径的长度
  • .GetPointAtDistance()返回沿路径指定距离

    的GLatLng。

    距离以米为单位指定

    如果路径短于



这应该可行(如果您包含该脚本并且您的多段线变量是折线):

  var latlng = polyline.GetPointAtDistance(polyline.Distance()*(想要的百分比)/ 100); 

当然,如果您的折线长度不变,计算长度会更有效率一旦使用它,每次你想在折线上找到一个点。

  var polylength = polyline.Distance(); 
var latlng = polylength *(想要的百分比)/ 100);


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 there that does the grunt work?

Google maps API v3thanks!

解决方案

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);

这篇关于latLng来自polyLine百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 21:38