我必须为公司制作地图,我必须将公司徽标放在一个标记上,并在另外10个标记上放置一个容器图标 但我不知道怎么做: 这是我目前的代码:(所以我的第一个标记带有我的标识,但是它是个人图像所以看不到标记) 我必须制作一个像“marker2”这样的新变量吗? 并为图标的每个位置创建新变量?
var nice = new google.maps.LatLng(43.7101728,7.2619532);
var centre = new google.maps.LatLng(43.7101728,7.2619532);
var marker;
var map;
function initialize() {
var mapOptions = {
zoom: 14,
center: nice,
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
marker = new google.maps.Marker({
map:map,
draggable:false,
animation: google.maps.Animation.DROP,
position: centre,
icon:'image/abi06B.png'
});
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
#map-canvas {
position: absolute;
height: 100%;
width:100%;
}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<div id="map-canvas">
</div>
答案 0 :(得分:0)
回答你的问题
do i have to make a new variable like "marker2" ?
这将是一个是和否。
看起来您可能无法100%确定这些代码的作用:
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
marker = new google.maps.Marker({
map:map,
draggable:false,
animation: google.maps.Animation.DROP,
position: centre,
icon:'image/abi06B.png'
});
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
行,如果要在'map-canvas'元素中创建Google地图,此函数会返回对地图对象的引用,以便您以后修改它。
然后,marker = new google.maps.Marker({ map:map,.....
使用您提供的设置制作标记,其中包括标题或图标图像。此函数还返回一个引用,该引用是对刚刚创建的标记的引用,用于将来可能需要修改标记(更改图标或删除)
所以......你需要做几次({1}}次,可能是在一个循环中。但是,如果您以后不需要参考来修改标记,则无需进行new google.maps.Marker
,只需使用marker2
答案 1 :(得分:0)
实际上我找到了一个解决方案,它&#39;看......业余主义,但它的工作
function initialize() {
var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(43.7101728,7.2619532)
}
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var image = 'image/abi06map.png';
var image2 = 'image/garbage3.png';
var Abi = new google.maps.Marker({
position: new google.maps.LatLng(43.7101728,7.2619532),
map: map,
icon: image
});
var Container1 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container2 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container3 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container4 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container5 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container6 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container7 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container8 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container9 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Container10 = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image2
});
var Cannes = new google.maps.Marker({
position: new google.maps.LatLng(43.301728,7.2219532),
map: map,
icon: image1
});
}
google.maps.event.addDomListener(window, 'load', initialize);
&#13;