开发者

Google Maps - Combine marker options and click event?

I have some problems combining a custom marker icon with my infoWindow.

Here is my js code:

    var micon = new GIcon();
    micon.image = "/path/to/my/icon.png";
    micon.iconSize = new GSize(25, 17);
    micon.iconAnchor = new GPoint(25, 17);

    markerOptions = {
        icon:micon
    }

    var point = new GLatLng(48.092757,11.645508);
    var marker = new GMarker(point, markerOptio开发者_Python百科ns)
    map2.addOverlay(marker);

This is working. I get my marker at the right position with my custom icon. Now I want to add an infowindow to my marker, so I added

    GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml('Some text');
    });

right after my var marker = new GMarker(point, markerOptions)

Now, on clicking my custom icon, I get an error (at firebug) called:

a is undefined

When removing my markerOptions at new Marker(), it works (but without my custom icon)

    var marker = new GMarker(point, markerOptions);
    GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml('Some text');
    });

    map2.addOverlay(marker);

to

    var marker = new GMarker(point);
    GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml('Some text');
    });

    map2.addOverlay(marker);

What's wrong with my code?


have you tried,

var marker = new GMarker(point, micon)


I solved my problem! I had to add micon.infoWindowAnchor = new GPoint(25, 17); to my GIcon().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜