这是我下面的代码,我选择一个图像来表示我的标记,图像太大了,有没有一种方法我可以调整我的图像也看起来更小,例如填充,imagesizeicon等
function initialize() {
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: center
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
for (var i=0; i<a.length;i++)
{
if(i == 0) iconImage = "image1.jpg";
else if(i == 1) iconImage = "image2.jpg";
marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: a[i],
icon: iconImage,
});
答案 0 :(得分:7)
使用google.maps.icon对象指定图标而不是简单图像文件名。在那里你可以设置size,例如
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
},
});
完整的工作示例(此html文档旁边需要marker.gif
文件)
<!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>