Mehrad Rafigh
Mehrad Rafigh

Reputation: 156

change icon of google maps marker

I am trying to change the marker icon in google maps. But it doesn't seem to work :/ Does any one of you have any tips how I can change the marker icon?

Here is the javascript code:

/*
    Google maps
*/
jQuery(document).ready(function() {
    var latlng = new google.maps.LatLng(50.92133, 6.92879);
    $('.map').gmap({'center': latlng,'zoom': 15, 'disableDefaultUI':true, 'callback': function() {
        var self = this;

        google.maps.Icon ic;
        ic = new google.maps.Icon({      
            url: 'icon.png'
        });

        self.setIcon(marker);
        self.addMarker({ 'position': this.get('map').getCenter() });

        }
    }); 
});

Upvotes: 1

Views: 2312

Answers (1)

Cole Pilegard
Cole Pilegard

Reputation: 582

self.setIcon(marker);

You are passing in an undefined variable here, but you also want to set the icon to the icon object you just made. This should be more what you're looking for.

var marker = new google.maps.Marker({
  position: self.getCenter(),
  map: self
});
marker.setIcon(ic);

Upvotes: 1

Related Questions