开发者

Change default marker for an image in GMaps API v3

I'm trying to adapt code (google maps window with a sidebar) I found at http://koti.mbnet.fi/ojalesa/boundsbox/makemarker_sidebar.htm for a personal blog .

What I want is to change the default marker for an image (always the same). All my attempts to recode have failed. Image is in folder images (images/monument.gif); I don't have for the moment an absolute URL.

I have tried to follow the API documentation and searching on Google, but no开发者_如何学JAVA luck.

var infoWindow = new google.maps.InfoWindow();
var markerBounds = new google.maps.LatLngBounds();
var markerArray = [];

function makeMarker(options){
var pushPin = new google.maps.Marker({map:map});
pushPin.setOptions(options);
google.maps.event.addListener(pushPin, "click", function(){
infoWindow.setOptions(options);
infoWindow.open(map, pushPin);
if(this.sidebarButton)this.sidebarButton.button.focus();
});
var idleIcon = pushPin.getIcon();
if(options.sidebarItem){
pushPin.sidebarButton = new SidebarItem(pushPin, options);
pushPin.sidebarButton.addIn("sidebar");
}
markerBounds.extend(options.position);
markerArray.push(pushPin);
return pushPin;
}

google.maps.event.addListener(map, "click", function(){
infoWindow.close();
});


This should work:

var infoWindow = new google.maps.InfoWindow();
var markerBounds = new google.maps.LatLngBounds();
var markerArray = [];

function makeMarker(options) {

    var pushPin = new google.maps.Marker({
        icon: 'images/monument.gif',
        map: map
    });

    pushPin.setOptions(options);

    google.maps.event.addListener(pushPin, "click", function() {
        infoWindow.setOptions(options);
        infoWindow.open(map, pushPin);
        if (this.sidebarButton) this.sidebarButton.button.focus();
    });

    if (options.sidebarItem) {
        pushPin.sidebarButton = new SidebarItem(pushPin, options);
        pushPin.sidebarButton.addIn("sidebar");
    }

    markerBounds.extend(options.position);
    markerArray.push(pushPin);
    return pushPin;
}

google.maps.event.addListener(map, "click", function() {
    infoWindow.close();
});

The only changes are the "icon" property in the MarkerOptions and and I removed the getIcon() call.


When you call makeMarker(), include icon:"images/monument.gif" in the options property list like this:

myPushPin = makeMarker({icon:"images/monument.gif", anotherOption:"anotherOptionValue"});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜