How can I check if a custom tooltip's upper left fits within the map bounds? I am using the code below but something is not right because 'myLatLng' is never within the map bounds. Thank you for your help in advance.
var scale = Math.pow(2, map.getZoom());
var nw = new google.maps.LatLng(
map.getBounds().getNorthEast().lat(),
map.getBounds().getSouthWest().lng()
);
var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
var worldCoordinate = map.getProjection().fromLatLngToPoint(marker.getPosition());
var pixelOffset = new google.maps.Point(
Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
);
var myLatLng = map.getProjection().fromPointToLatLng(pixelOffset);
if (map.getBounds().contains(myLatLng)) {
// it's within bounds
}