更改GMaps API v3中图像的默认标记

问题描述

| 我正在尝试修改http://koti.mbnet.fi/ojalesa/boundsbox/makemarker_sidebar.htm中用于个人博客的代码(带有侧边栏的Google Maps窗口)。 我想要的是更改图像的默认标记(始终相同)。 我所有的重新编码尝试都失败了。图片在文件夹图片中(images / monument.gif);我暂时没有绝对网址。 我试图遵循API文档并在Google上进行搜索,但是没有运气。
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,function(){
infoWindow.close();
});
    

解决方法

这应该工作:
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,function() {
    infoWindow.close();
});
唯一的变化是MarkerOptions中的\“ icon \”属性,并且我删除了getIcon()调用。     ,调用
makeMarker()
时,请将the3ѭ包括在options属性列表中,如下所示:
myPushPin = makeMarker({icon:\"images/monument.gif\",anotherOption:\"anotherOptionValue\"});
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...