i'm need to fitBounds few markers on my map and also need show infowindow on one of them. And all this stuff should be inside map viewport. I'm trying to use this code to get bounds of InfoWindow top left, top right corners and 2 markers:
function calculateWaypointsBounds(attraction, destination, client, infoBox, map){
const bounds = new google.maps.LatLngBounds();
bounds.extend(new google.maps.LatLng(attraction.lat, attraction.lon));
bounds.extend(new google.maps.LatLng(client.lat, client.lon));
bounds.extend(new google.maps.LatLng(destination.lat, destination.lon));
const div = infoBox.content_;
const projectionCoords = infoBox.getProjection().fromLatLngToContainerPixel(new google.maps.LatLng(attraction.lat, attraction.lon));
const leftTop = new google.maps.Point(projectionCoords.x - div.offsetWidth / 2, projectionCoords.y - 400);
const rightTop = new google.maps.Point(projectionCoords.x + div.offsetWidth / 2, projectionCoords.y - 400);
const ltCoords = infoBox.getProjection().fromContainerPixelToLatLng(leftTop);
const rtCoords = infoBox.getProjection().fromContainerPixelToLatLng(rightTop);
bounds.extend(ltCoords);
bounds.extend(rtCoords); //InfoWindow always shows above marker, so i'm need only top left and top right corners.
return bounds;
}
But looks like my idea wrong. How can i do thats infoWindow and 2 of my markers are allways inside map viewport.