如何获取折线中两个端点之间的所有 LatLng 点
我正在从事 GMap 定制工作。我想要一个浮动圆移动穿过多段线。我的问题是,我们能否在特定间隔后获取折线中的所有 LatLng 点,例如,以 100 米为间隔的所有 LatLng 点。我的折线代码是:
/** polyline **/
var tpath = [
new google.maps.LatLng(15.508718,73.839337),
new google.maps.LatLng(15.511457,73.839165)
];
var travelPath = new google.maps.Polyline({
path : tpath,
map : map,
geodesic : true,
strokeColor : '#000',
strokeOpacity : 0.7,
strokeWeight : 1
});
我只得到最终的 LatLng 值。我想要跨折线的值。
提前致谢。
I am working on GMap customization. I want a floating circle to move across a a Polyline. My question is that can we get all LatLng points in a Polyline after a specific interval for eg, all LatLng at interval of 100meters. My polyline code is:
/** polyline **/
var tpath = [
new google.maps.LatLng(15.508718,73.839337),
new google.maps.LatLng(15.511457,73.839165)
];
var travelPath = new google.maps.Polyline({
path : tpath,
map : map,
geodesic : true,
strokeColor : '#000',
strokeOpacity : 0.7,
strokeWeight : 1
});
i get only the end LatLng values. I want the values across the Polyline.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 google.maps.geometry.spherical.computeHeading(startPoint, endPoint) 来获取标题。
然后使用 google.maps.geometry.spherical.computeDistanceBetween(startPoint, endPoint) 计算距离
如果距离为 475m 并且您想要进行约 100 次跳跃,只需执行 475/round(475/100) 即可计算距离< /strong> 你每次都想移动圆圈。 round(475/100) 将为您提供应该移动圆圈的次数(迭代)。
然后你可以使用computeOffset(from:LatLng,距离:number,heading:number,radius?:number)
然后你可以使用computeOffset(circleCenter,distance,heading)在for循环中获取新的圆心点迭代量上面计算的。不要忘记在循环中包含延迟。
You could use google.maps.geometry.spherical.computeHeading(startPoint, endPoint) to get the heading.
Then compute the distance with google.maps.geometry.spherical.computeDistanceBetween(startPoint, endPoint)
If the distance is 475m and you want to make ~100 jumps just do 475/round(475/100) to calculate the distance you want to move the circle each time. round(475/100) will give you how many times (iterations) you should move the circle.
Then you could use computeOffset(from:LatLng, distance:number, heading:number, radius?:number)
Then you can use computeOffset(circleCenter, distance, heading) to get the new cirecle center point in a for loop the amount of iterations calculated above. Don't forget to include a delay in your loop.
我不知道如何使用谷歌地图API获取它,但你可以画一条线来手动获取从开始和结束的点。这是简单的数学,画一条线并计算。
I don't know how to get it with google maps api but you can draw a line to get the points from a start and end manually. It's simple math for a drawing a line and calculate.
在返回您单击的折线后,您可以使用 GoogleMap.OnPolylineClickListener 在折线上设置单击侦听器。
确保通过设置使您的折线可点击。
lineOptions.clickable(true);
You can set On click listener on Polyline by using GoogleMap.OnPolylineClickListener, after it returns the polyline you click on.
be sure to make your polyline clickable by setting.
lineOptions.clickable(true);