I had a panel 400 pixels wide on my right hand.
Starting with a call to zoomWithPoints, which transmits two points for inclusion in the view, the following code implements the approach described below: 1) Scaling to borders 2) Using the obtained scale scale, calculate how much you need to add to "maxLon" 3) Zoom to the borders.
function zoomToBbox(minLat, minLon, maxLat, maxLon) { var southwest = new google.maps.LatLng(minLat, minLon); var northeast = new google.maps.LatLng(maxLat, maxLon); var bounds = new google.maps.LatLngBounds(southwest, northeast); map.fitBounds(bounds); } function zoomWithPoints(lat1, lon1, lat2, lon2) { var maxLat = Math.max(lat1, lat2); var maxLon = Math.max(lon1, lon2); var minLat = Math.min(lat1, lat2); var minLon = Math.min(lon1, lon2); zoomToBbox(minLat, minLon, maxLat, maxLon); var z = map.getZoom();
source share