0
我正在使用Google地圖切換到leaflet.js。我在Google地圖中做過的一件事,似乎無法在leaflet.js中找到,它計算從地圖中心(即搜索位置)到地圖邊上的半徑。因爲您可以放大或縮小人們正在看的區域可能會發生顯着變化。 下面的代碼顯示了我爲了用google地圖做的那幾行。有人可以指出我關於leaflet.js的正確方向嗎?leaflet.js計算從中心到邊界的半徑
// viewport stores the recommended viewport for the returned result.
// (LatLngBounds)
viewportLatLngBounds = zip.get("location").geometry.viewport;
this.map.fitBounds(viewportLatLngBounds);
this.collection.latitude = viewportLatLngBounds.getCenter().lat();
this.collection.longitude = viewportLatLngBounds.getCenter().lng();
// calculate radius
// get distance..
// from (lat of NE corner), (lng of center)
// to (lat of center), (lng of center)
topCenterLatLng = new google.maps.LatLng(viewportLatLngBounds.getNorthEast().lat(), viewportLatLngBounds.getCenter().lng());
metersRadius = google.maps.geometry.spherical.computeDistanceBetween(viewportLatLngBounds.getCenter(), topCenterLatLng);
this.collection.radius = metersRadius/1000;
this.collection.radiusUnits = "km";