使用google.maps.icon对象来指定图标而不是简单的图像文件名。在那里你可以设置大小,例如
marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: a[i],
icon: {
size: new google.maps.Size(width, height),
scaledSize: new google.maps.Size(width, height),
url: iconImage
},
});
完整的工作示例(您需要marker.gif
此 html 文档旁边的文件)
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API V3 Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 11,
center: new google.maps.LatLng(52.3727, 4.8985),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(52.3727, 4.8985),
icon: {
size: new google.maps.Size(20, 20),
scaledSize: new google.maps.Size(20, 20),
url: "marker.gif"
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>