HTML Google地图无法查看标记

时间:2016-12-27 18:49:21

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

我正在尝试使用标记创建地图。 但在下面的代码中,我看不到标记。

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps - pygmaps </title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=visualization&sensor=true_or_false"></script>
<script type="text/javascript">
    function initialize() {
        var centerlatlng = new google.maps.LatLng(37.427000, -122.145000);
        var myOptions = {
            zoom: 16,
            center: centerlatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

        var latlng = new google.maps.LatLng(37.427000, -122.145000);
        var img = new google.maps.MarkerImage('C:\Python27\lib\site-packages\gmplot\markers\D8BFD8.png');
        var marker = new google.maps.Marker({
        title: "no implementation",
        icon: img,
        position: latlng
        });
        marker.setMap(map);

        var latlng = new google.maps.LatLng(37.428000, -122.146000);
        var img = new google.maps.MarkerImage('C:\Python27\lib\site-packages\gmplot\markers\6495ED.png');
        var marker = new google.maps.Marker({
        title: "no implementation",
        icon: img,
        position: latlng
        });
        marker.setMap(map);

        var latlng = new google.maps.LatLng(37.429000, -122.144000);
        var img = new google.maps.MarkerImage('C:\Python27\lib\site-packages\gmplot\markers\000000.png');
        var marker = new google.maps.Marker({
        title: "no implementation",
        icon: img,
        position: latlng
        });
        marker.setMap(map);

    }
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
    <div id="map_canvas" style="width: 100%; height: 100%;"></div>
</body>
</html>

例如:C:\Python27\lib\site-packages\gmplot\markers\6495ED.png顺便说一句。我可以看到有图像,但图像不会出现在地图上。谁能说我怎么能解决这个问题?

2 个答案:

答案 0 :(得分:0)

您的路径不正确。例如使用此URL更改它。 https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png 你会看到标记。

您可以在此处找到有关标记图标的更多信息 https://developers.google.com/maps/documentation/javascript/examples/icon-complex?hl=ru

答案 1 :(得分:0)

最近我遇到了类似问题,只是使用正斜杠而不是反斜杠来解决