Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何找到具有两个以上坐标的google地图多段线的中心?_Javascript_Google Maps_Center_Polyline - Fatal编程技术网

Javascript 如何找到具有两个以上坐标的google地图多段线的中心?

Javascript 如何找到具有两个以上坐标的google地图多段线的中心?,javascript,google-maps,center,polyline,Javascript,Google Maps,Center,Polyline,我正在从事asp.NETMVC3项目,我们正在使用谷歌地图。我想在多边形线的中心显示标记。 我正在使用下面的代码 var start = new google.maps.LatLng( MyMapCordinates[0].lat(), MyMapCordinates[0].lng() ); var End = new google.maps.LatLng( MyMapCordinates[MyMapCordinates.length - 1].lat(), My

我正在从事asp.NETMVC3项目,我们正在使用谷歌地图。我想在多边形线的中心显示标记。 我正在使用下面的代码

var start = new google.maps.LatLng(
    MyMapCordinates[0].lat(),
    MyMapCordinates[0].lng()
);
var End = new google.maps.LatLng(
    MyMapCordinates[MyMapCordinates.length - 1].lat(),
    MyMapCordinates[MyMapCordinates.length - 1].lng()
);
debugger
var inBetween = google.maps.geometry.spherical.interpolate(start, End, 0.5);
var marker= new google.maps.Marker({
    position: inBetween
});

使用具有两个坐标的多段线时效果良好。但对于具有三个以上坐标的多段线,它失败了。请建议

插值方法仅适用于两组坐标。computeLength()方法看起来像是要计算多个点的距离,然后做一些数学运算来找到中间点


这有用吗?

嗨,用户211010,谢谢。我已经使用computeLength()计算了多段线的长度,并将其除以2,得到了多段线的一半。此外,我还使用computeOffset方法找到中心线,以便在该位置放置标记。但这仍然不适用于坐标超过两个的多段线。多段线的总长度,开始和结束之间的区别,眼睛的中心看起来是什么,一个加权的二维形状?