Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

info window custom close button

I have an instance of google.maps.InfoWindow, and it has a custom closing button. Which is triggered by onClick event. However, if I click on close button, the info window is closed, which is expected, but a new marker appears on the map, on a place where info window use to be. It looks like the onClick="infoWindow.close()" is the placeReclameMarker(event.latLng); simultaneously.

    var map;
    var infoWindow;
    function initialize() {
        var latlng = new google.maps.LatLng(47.030698, 28.850098);
        var myOptions = {
            zoom: 15,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(
            document.getElementById("map_canvas"), myOptions);

        google.maps.event.addListener(map, 'click', function (event) {
            placeReclameMarker(event.latLng);
        });

    }

    function placeReclameMarker(location) {

        var marker = new google.maps.Marker({
            position: location,
            draggable: true,
            map: map
        });
        google.maps.event.addListener(marker, 'rightclick', function () {
            infoWindow = new google.maps.InfoWindow({
                content: '<input type="button" onclick="infoWindow.close()">'
            });
            infoWindow.open(map, marker);
        });
    }
like image 894
alagar Avatar asked Apr 27 '26 04:04

alagar


1 Answers

i'm not sure you can visit infoWindow variable in infoWindow object inner. try:

content: '<input type="button" onclick="parent.infoWindow.close()">'

or

content: '<input type="button" onclick="parent.parent.infoWindow.close()">'

or

content: '<input type="button" onclick="alert(infoWindow)">'

infoWindow variable must not to be undefined.

good luck

like image 156
Koerr Avatar answered Apr 29 '26 19:04

Koerr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!