简体   繁体   English

在 Google 地图点之间添加线

[英]Add line between Google Maps points

I have two points may have different lengths.我有两个点可能有不同的长度。 Among them is a line.其中有一条线。 I need Take the value between these 2 points.我需要取这 2 点之间的值。 And then later add a line of another color on top .然后在上面添加一条另一种颜色的线。 But this line should be between 1 and 1000 meters, according to user choice and according to the size of 2 points.但是这条线应该在1到1000米之间,根据用户选择,根据2个点的大小。 If they are higher than 1000 meters, I add a line with or less size.如果它们高于 1000 米,我会添加一条或更少尺寸的线。 How to do it with Google Maps ?如何用谷歌地图做到这一点?

var flightPlanCoordinates = [
    {lat: marker.getPosition().lat(), lng: marker.getPosition().lng()},
    {lat: satelite.getPosition().lat(), lng: satelite.getPosition().lng()}
];
var flightPath = new google.maps.Polyline({
    path: flightPlanCoordinates,
    geodesic: true,
    strokeColor: '#FF9800',
    strokeOpacity: 1.0,
    strokeWeight: 4
});

flightPath.setMap(map);

Ex:前任:

在此处输入图片说明

What did wanted it can be solved with the interpolate function.想要的东西可以用插值函数解决。 Just calculate the distance between 2 points and get the percentage of the film you want and put on interpolate .只需计算 2 点之间的距离并获得您想要的电影的百分比并进行插值。

 google.maps.geometry.spherical.interpolate(Point1, Point2, 10%);

Interpolate() 插()

Calculating the distance between two points is really easy with the help of the Geometry library.在几何库的帮助下,计算两点之间的距离非常容易。 All you have to do is to call the computeDistanceBetween() function and pass it two LatLng objects.您所要做的就是调用 computeDistanceBetween() 函数并将其传递给两个 LatLng 对象。

 var point1 = new google.maps.LatLng(marker.getPosition().lat(), marker.getPosition().lng());
 var point2 = new google.maps.LatLng(satelite.getPosition().lat(), satelite.getPosition().lng());
 var distance = google.maps.geometry.spherical.computeDistanceBetween(point1, point2);

 alert('distance is '+distance+'m');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM