简体   繁体   中英

HTML Google Maps can't see markers

I am trying to create a map with markers. But in the below code I can't see the markers.

<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>

For example: C:\\Python27\\lib\\site-packages\\gmplot\\markers\\6495ED.png exists by the way. I can see that there are images but images dont appear on the map. Can anyone say how can I fix this situation?

Your path is incorrect. Change it with for example this URL. https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png and you will see markers.

You can find more about marker icons here https://developers.google.com/maps/documentation/javascript/examples/icon-complex?hl=ru

我最近遇到了类似的问题,只是使用正斜杠而不是反斜杠修复了它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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