public static int GetBoundsZoomLevel(LatLngBounds bounds, int widthPx, int heightPx) { var latFraction = (LatRad(bounds.NorthLat) - LatRad(bounds.SouthLat)) / Math.PI; var lngDiff = bounds.EastLng - bounds.WestLng; var lngFraction = ((lngDiff < 0) ? (lngDiff + 360) : lngDiff) / 360; var latZoom = GetFractionZoomLevel(heightPx, DefaultWorldPx, latFraction); var lngZoom = GetFractionZoomLevel(widthPx, DefaultWorldPx, lngFraction); return(Math.Min(latZoom, Math.Min(lngZoom, 21))); }
public static LatLngBounds BoundsOf(IEnumerable <LatLng> points) { LatLngBounds result = null; foreach (var point in points) { if (point == null) { continue; } if (result == null) { result = BoundsOf(point); } else { result.ExtentToContain(point); } } return(result); }