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";