上传到服务器后谷歌地图标记没有显示,本地工作正常

时间:2015-01-23 14:56:24

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

我正在尝试实现一个启用了谷歌地图的简单页面,但我遇到的问题是,在将文件上传到托管后我的谷歌地图标记没有显示,它在本地工作正常。

我尝试使用自定义标记和默认标记,问题是相同的,它在本地工作,但在上传后不会。

这是我正在使用的脚本

/*GOOGLE MAPS*/

function initialize() {

        // Declare map style
        var grayscale = [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}];     

        var mapOptions = {
          center: {lat: 46.211000, lng: 16.913157},
          zoom: 13,
          scrollwheel: false

        };

        var map = new google.maps.Map(document.getElementById('map-canvas'),
                mapOptions);

        // Change map style
        map.setOptions({styles: grayscale});

        var image = 'img/vemo-google-map-marker.png';
        var marker = new google.maps.Marker({
                position: {lat: 46.211000, lng: 16.913157},
                map: map,
                title: "VEMO TRADE d.o.o.",
                icon: image,
        });

}
google.maps.event.addDomListener(window, 'load', initialize);

enter image description here

1 个答案:

答案 0 :(得分:5)

您需要在此指定整个绝对路径:

var image = '//YOUR_DOMAIN/img/vemo-google-map-marker.png';