谷歌地图自定义markerimage无法正常工作

时间:2013-01-02 15:45:54

标签: javascript google-maps-api-3

出于某种原因,每当我尝试为我的地图使用自定义标记图像时,它只显示默认值。这是我的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Google Maps JavaScript API v3 Example: Marker Simple</title>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false" type=
        "text/javascript"></script>
        <script type="text/javascript">        
            function initialize() {
                var mapOptions = {
                        zoom: 3,
                        center: new google.maps.LatLng(-25.363882,131.044922),
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };
                map = new google.maps.Map(document.getElementById('map'), mapOptions);
                var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(-25.363882,131.044922),
                        map: map,
                        title: 5,
                        icon: new google.maps.MarkerImage('http://www.gettyicons.com/free-icons/108/gis-gps/png/24/needle_left_yellow_2_24.png',
                                new google.maps.Size(24, 24),
                                new google.maps.Point(0,0),
                                new google.maps.Point(0, 24))
                    });
            }
        </script>
    </head>
    <body onload="initialize()">
        <div id="map" style="width: 780px; height: 480px"></div>
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

问题出在你的标题选项中,必须是一个字符串。所以用"5"替换它,它会起作用!

参见演示: http://jsbin.com/uwudab/1/edit