【发布时间】:2021-12-30 22:51:39
【问题描述】:
我正在使用 Google Maps API JavaScript。我的用例是我需要在地图上绘制坐标(lat、lng)(创建标记)并通过折线将它们连接起来。坐标将非常接近,因此当我尝试绘制它们时,它们会隐藏在第一个标记后面。所以我找到了中心并尝试缩放,以便所有标记都在地图上可见。 我使用边界来找到中心,但我无法将其缩放到中心坐标。我用 map.fitBounds(latlng); 它适合屏幕上的坐标。 但我想要实现的是使折线(连接所有坐标)始终水平并将其缩放到中心坐标。
enter code herevar bounds = new google.maps.LatLngBounds();
for (i = 0; i < temp.length; i++) {
bounds.extend(temp[i]);
}
var latlng = bounds.getCenter();
map.setCenter(latlng);
由于坐标总是不同的,折线将在任何方向,但我总是想在地图上水平显示它。 我得到什么: enter image description here
我想要达到的目标:
任何建议将不胜感激。 提前致谢。
【问题讨论】:
标签: google-maps google-maps-api-3 google-maps-markers google-polyline