给定一组纬度和经度点,如何计算该集合中心点的纬度和经度(也就是将所有点的视图居中的点)?
编辑:我用过的Python解决方案:
Convert lat/lon (must be in radians) to Cartesian coordinates for each location.
X = cos(lat) * cos(lon)
Y = cos(lat) * sin(lon)
Z = sin(lat)
Compute average x, y and z coordinates.
x = (x1 + x2 + ... + xn) / n
y = (y1 + y2 + ... + yn) / n
z = (z1 + z2 + ... + zn) / n
Convert average x, y, z coordinate to latitude and longitude.
Lon = atan2(y, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将InfoWindow添加到路线路线.有很多例子可以在标记上的事件监听器上添加InfoWindow.
但是,如何将InfoWindow移动到从一个标记到另一个标记的实际计划路线上.有人之前已经尝试过问这个问题,但没有回复(InfoWindow on Directions Route).
无论如何,我做了很多谷歌搜索,只发现了一个与此类似的问题,但是再次没有回应.
我infowindow.open(map,this)在回调中尝试了标记上的事件,但它会在标记位置打开InfoWindow.它只是我希望显示像谷歌一样的持续时间和距离.像附图中的东西
var infowindow2 = new google.maps.InfoWindow();
distanceService.getDistanceMatrix(distanceRequest, function (response, status) {
if (status == "OK") {
infowindow2.setContent(response.rows[0].elements[0].distance.text + "<br>" + response.rows[0].elements[0].duration.text + " ")
}
else {
alert("Error: " + status)
}
})
infowindow2.open(map, this);
Run Code Online (Sandbox Code Playgroud)

javascript google-maps infowindow directions google-directions-api