我创建了以下代码来显示地图
<script>
var myLatlng;
var mapOptions;
var map;
var marker;
function initialize() {
myLatlng = new google.maps.LatLng(-25.363882,131.044922);
mapOptions = {zoom: 4,center: myLatlng,mapTypeId: google.maps.MapTypeId.ROADMAP }
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// marker 1
marker = new google.maps.Marker({position: myLatlng, map: map,title: 'Hello World!'});
// marker 2
myLatlng = new google.maps.LatLng(-24.363882,131.044922);
marker = new google.maps.Marker({position: myLatlng, map: map,title: 'Hello Ciccio!'});
// marker 3
myLatlng = new google.maps.LatLng(-20.363882,131.044922);
marker = new google.maps.Marker({position: myLatlng, map: map,title: 'Hello Pippo!'});
}
function writeMap(){
google.maps.event.addDomListener(window, 'load', initialize);
}
function addMarker(){
// marker 4
myLatlng = new google.maps.LatLng(-18.363882,131.044922);
marker = new google.maps.Marker({position: myLatlng, map: map,title: 'Hello PLUTO!'});
}
</script>
如果我在有效的初始化函数中调用 addMarker(),如果我尝试在 HTML 代码中调用该函数,它不会。
执行完初始化函数后如何创建标记?
谢谢。恩里科