简体   繁体   English

Google Maps API:为什么不能使用相对图标路径设置标记的图标?

[英]Google maps API: Why can't I set the icon of my markers by using relative icon paths?

These are my marker options 这些是我的标记选项

var markerOptions = {
                clickable: true,
                draggable: false,
                flat: true,
                map: map,
                icon: 'food.png',
                optimized: true,
                position: pos,
                title: name,
                visible: true,
                animation:google.maps.Animation.DROP,
            };

'food.png' is in the same folder of the javascript file. 'food.png'位于javascript文件的同一文件夹中。 However it doesn't work. 但是,它不起作用。

If I use the full http path it works fine. 如果我使用完整的http路径,则可以正常工作。 For example 例如

http://localhost/javascript/food.png

is it possible to avoid this? 有可能避免这种情况吗?

The icon image needs to be in the same directory as the HTML page it is being referenced from, not the same directory as the javascript. 图标图像必须与要从其引用的HTML页面位于同一目录中,而不是与javascript位于同一目录中。

Update: as webaware pointed out a relative path to the icon should be relative to the directory containing the HTML document. 更新:如webaware所指出,图标的相对路径应相对于包含HTML文档的目录。

The example from the documentation works fine both on the Google site and locally on my machine. 文档中示例在Google网站和我的计算机上均可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM