0

为什么我的标记没有出现?
我也尝试不使用“marker.show”行,但标记似乎没有出现。

<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 JavaScript API v3 Example: Custom Control</title>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false">    </script>
<script type="text/javascript" src="ZoomPanControl.js"></script>
<script type="text/javascript">
function initialize() {  
    var myOptions = {  
        zoom: 10,  
        center: new google.maps.LatLng(47.3732589, 8.2382168),  
        mapTypeId: google.maps.MapTypeId.ROADMAP,  
        navigationControl: true }  
    var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);  
    var marker = new google.maps.Marker({ position: google.maps.LatLng(47.3732589, 8.2382168), title: 'x', map:map});  
    marker.show;  
};
</script></head>  
<body style="margin:0px; padding:0px;" onload="initialize()">  
<div id="map_canvas" style="width:100%; height:100%"></div>  
</body></html>  
4

2 回答 2

6

这应该可以解决问题:

var marker = new google.maps.Marker();
marker.setPosition(new google.maps.LatLng(47.3732589, 8.2382168));
marker.setMap(map);
于 2013-03-25T14:15:41.493 回答
4

您很接近,但new在添加position. 它应该如下所示:

var marker = new google.maps.Marker({ position: new google.maps.LatLng(47.3732589, 8.2382168), title: 'x', map:map});
于 2013-03-25T14:14:42.120 回答