传递图标作为参数不起作用 - 谷歌地图

时间:2016-04-30 09:06:40

标签: javascript google-maps google-maps-api-3

:)我试图将一个图标作为一个参数传递给一个简单的标记丢弃函数,但我似乎无法正确传递它,即使我已尝试使用单引号和双引号。所以我有以下功能和使用它的代码。

function addMarkerWithTimeout(position, the_image, timeout) {  //Marker dropping function
    window.setTimeout(function(the_image) {
    markers.push(new google.maps.Marker({
        position: position,
        map: map,
        draggable: false,
        icon: the_image,      //Hard-typing the url here works perfectly
        scale: 3,
        animation: google.maps.Animation.DROP }));
    }, timeout);
}

var start_image = '../icons/favicon.ico';                      //The icon local url
addMarkerWithTimeout(routeCoordinates[0], start_image, 200);   //Calling the function

1 个答案:

答案 0 :(得分:1)

从window.setTimeout

中删除the_image
function addMarkerWithTimeout(position, the_image, timeout) {  //Marker 
    window.setTimeout(function() {