Auto-panning map so that infowindow is fully visible

393 Views Asked by At

i am setting marker to place center of screen when it click event is trigger by user from google map. but the issue arrived that info window content is not fully visible within view port as u can see in picture below. How can i Auto-panning map by code so that info window is fully visible within view port. i disabled scrolling within content of info window.

I Half content is not showing within view port

1

There are 1 best solutions below

1
Jd Akram On

I found solution in StackOverFlow. By the way thanks Stackoverflow team.

google.maps.Map.prototype.panToWithOffset = function(latlng, offsetX, offsetY) {
    var map = this;
    var ov = new google.maps.OverlayView();
    ov.onAdd = function() {
        var proj = this.getProjection();
        var aPoint = proj.fromLatLngToContainerPixel(latlng);
        aPoint.x = aPoint.x+offsetX;
        aPoint.y = aPoint.y+offsetY;
        map.panTo(proj.fromContainerPixelToLatLng(aPoint));
    }; 
    ov.draw = function() {}; 
    ov.setMap(this); 
};

and called this function when marker is clicked.