Marker click event is not firing











up vote
0
down vote

favorite












I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.



To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.



However, this doesn't work, the marker is set but the click event is not attached.



Attaching a click event to the map works.



Does anybody have any suggestions about what could be causing this?



init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}

loadScript(url) {
const script = document.createElement('script');

script.type = 'text/javascript';

script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);

setTimeout(() => {
this.initMap();
}, 500);
}

initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};

const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});

const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});

map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});

marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}









share|improve this question


















  • 1




    Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
    – boateng
    Nov 9 at 15:16








  • 1




    The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
    – geocodezip
    Nov 9 at 15:48










  • Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
    – Scott Francis
    Nov 12 at 14:24










  • In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
    – Scott Francis
    Nov 16 at 7:09















up vote
0
down vote

favorite












I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.



To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.



However, this doesn't work, the marker is set but the click event is not attached.



Attaching a click event to the map works.



Does anybody have any suggestions about what could be causing this?



init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}

loadScript(url) {
const script = document.createElement('script');

script.type = 'text/javascript';

script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);

setTimeout(() => {
this.initMap();
}, 500);
}

initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};

const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});

const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});

map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});

marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}









share|improve this question


















  • 1




    Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
    – boateng
    Nov 9 at 15:16








  • 1




    The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
    – geocodezip
    Nov 9 at 15:48










  • Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
    – Scott Francis
    Nov 12 at 14:24










  • In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
    – Scott Francis
    Nov 16 at 7:09













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.



To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.



However, this doesn't work, the marker is set but the click event is not attached.



Attaching a click event to the map works.



Does anybody have any suggestions about what could be causing this?



init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}

loadScript(url) {
const script = document.createElement('script');

script.type = 'text/javascript';

script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);

setTimeout(() => {
this.initMap();
}, 500);
}

initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};

const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});

const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});

map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});

marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}









share|improve this question













I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.



To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.



However, this doesn't work, the marker is set but the click event is not attached.



Attaching a click event to the map works.



Does anybody have any suggestions about what could be causing this?



init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}

loadScript(url) {
const script = document.createElement('script');

script.type = 'text/javascript';

script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);

setTimeout(() => {
this.initMap();
}, 500);
}

initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};

const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});

const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});

map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});

marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}






google-maps-api-3 google-maps-markers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 14:43









Scott Francis

192




192








  • 1




    Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
    – boateng
    Nov 9 at 15:16








  • 1




    The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
    – geocodezip
    Nov 9 at 15:48










  • Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
    – Scott Francis
    Nov 12 at 14:24










  • In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
    – Scott Francis
    Nov 16 at 7:09














  • 1




    Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
    – boateng
    Nov 9 at 15:16








  • 1




    The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
    – geocodezip
    Nov 9 at 15:48










  • Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
    – Scott Francis
    Nov 12 at 14:24










  • In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
    – Scott Francis
    Nov 16 at 7:09








1




1




Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16






Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16






1




1




The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48




The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48












Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
– Scott Francis
Nov 12 at 14:24




Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the client param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
– Scott Francis
Nov 12 at 14:24












In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09




In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I make a few change and works






const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});

map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});

marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227914%2fmarker-click-event-is-not-firing%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I make a few change and works






    const marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Click to zoom',
    icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
    });

    map.addListener('center_changed', function () {
    // 3 seconds after the center of the map has changed, pan back to the
    // marker.
    window.setTimeout(function () {
    map.panTo(marker.getPosition());
    }, 3000);
    });

    marker.addListener('click', function () {
    map.setZoom(8);
    map.setCenter(marker.getPosition());
    });
    marker.setMap(map);








    share|improve this answer

























      up vote
      0
      down vote













      I make a few change and works






      const marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Click to zoom',
      icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
      });

      map.addListener('center_changed', function () {
      // 3 seconds after the center of the map has changed, pan back to the
      // marker.
      window.setTimeout(function () {
      map.panTo(marker.getPosition());
      }, 3000);
      });

      marker.addListener('click', function () {
      map.setZoom(8);
      map.setCenter(marker.getPosition());
      });
      marker.setMap(map);








      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I make a few change and works






        const marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Click to zoom',
        icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
        });

        map.addListener('center_changed', function () {
        // 3 seconds after the center of the map has changed, pan back to the
        // marker.
        window.setTimeout(function () {
        map.panTo(marker.getPosition());
        }, 3000);
        });

        marker.addListener('click', function () {
        map.setZoom(8);
        map.setCenter(marker.getPosition());
        });
        marker.setMap(map);








        share|improve this answer












        I make a few change and works






        const marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Click to zoom',
        icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
        });

        map.addListener('center_changed', function () {
        // 3 seconds after the center of the map has changed, pan back to the
        // marker.
        window.setTimeout(function () {
        map.panTo(marker.getPosition());
        }, 3000);
        });

        marker.addListener('click', function () {
        map.setZoom(8);
        map.setCenter(marker.getPosition());
        });
        marker.setMap(map);








        const marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Click to zoom',
        icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
        });

        map.addListener('center_changed', function () {
        // 3 seconds after the center of the map has changed, pan back to the
        // marker.
        window.setTimeout(function () {
        map.panTo(marker.getPosition());
        }, 3000);
        });

        marker.addListener('click', function () {
        map.setZoom(8);
        map.setCenter(marker.getPosition());
        });
        marker.setMap(map);





        const marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Click to zoom',
        icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
        });

        map.addListener('center_changed', function () {
        // 3 seconds after the center of the map has changed, pan back to the
        // marker.
        window.setTimeout(function () {
        map.panTo(marker.getPosition());
        }, 3000);
        });

        marker.addListener('click', function () {
        map.setZoom(8);
        map.setCenter(marker.getPosition());
        });
        marker.setMap(map);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 10:19









        LDS

        1946




        1946






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227914%2fmarker-click-event-is-not-firing%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check