Changing data in the info window with Google Map markers

前端 未结 4 728
忘掉有多难
忘掉有多难 2021-01-02 12:24

I\'ve followed this tutorial to create a custom Google Map. I\'ve included a few other elements such as linking it up to Wordpress and clustering the markers.

It\'s

4条回答
  •  无人及你
    2021-01-02 13:03

    i had a similar problem, i figure this out, to change the content in marker infowindow

        var marker = new MarkerWithLabel({
            id: "costume_ID",/*<---this is the start of the trick*/
            position: new google.maps.LatLng(lat,lon),
            icon: "../images/icon-bla.png",
            map: map,
            title: 'bla',
            labelContent: 'bla,bla,
            labelClass: "labels", 
            labelStyle: {opacity: 1.0}
        })
        google.maps.event.addListener(marker, 'click', (function() {
            return function(){
            infowindow.setContent(infor(this.id));/*<--- here is the trick*/
            infowindow.open(map, this);
            map.setCenter(this.getPosition());
        }});
    

    and than set the function that will output whatever you whant, if you have the info in variables.

        function infor(im){
            return "
    INFOWINDOW
    Date: "+var[im].date+"
    Sync: "+var[im].sync+"...bla,bla,bla
    "; }/*THIS FUNCTION RETURN THE STING TO SHOW ION THE INFOWINDOW*/

提交回复
热议问题