在谷歌地圖上繪製矩形,我需要知道西北和東南的點,首先構造一個LatLngbounds。如何繪製谷歌地圖矩形如果我只知道它的大小和東北點
在我的情況下,我想繪製一個具有特定西北點和大小(例如100米寬和100米高)的矩形。我不知道最高點。
我害怕幾何學和地質學。我知道東南可以來自一些公式。只是想知道是否有API或簡單的方法來做到這一點?
在谷歌地圖上繪製矩形,我需要知道西北和東南的點,首先構造一個LatLngbounds。如何繪製谷歌地圖矩形如果我只知道它的大小和東北點
在我的情況下,我想繪製一個具有特定西北點和大小(例如100米寬和100米高)的矩形。我不知道最高點。
我害怕幾何學和地質學。我知道東南可以來自一些公式。只是想知道是否有API或簡單的方法來做到這一點?
您可以編寫一個這樣的功能:
// Given the LatLng of a northwest corner, and the number of meters to
// measure east and south, return the LatLngBounds for that rectangle
function makeBounds(nw, metersEast, metersSouth) {
var ne = google.maps.geometry.spherical.computeOffset(
nw, metersEast, 90
);
var sw = google.maps.geometry.spherical.computeOffset(
nw, metersSouth, 180
);
return new google.maps.LatLngBounds(sw, ne);
}
這裏是一個working example。
參見computeOffset在幾何庫中。
computeOffset(來源:經緯度,距離:號,標題:數半徑:數)
喜歡的東西(未測試):
var NorthEast = google.maps.geometry.spherical.computeOffset(NorthWest, width, 90);
var SouthWest = google.maps.geometry.spherical.computeOffset(NorthWest, height, 180);
var SouthEast = google.maps.LatLng(SouthWest.lat(),NorthEast.lng());
一定要包括geometry library
測試。 IT完美地工作 – GingerJim