在javascript中,你想什么时候使用它:
(function(){
//Bunch of code...
})();
Run Code Online (Sandbox Code Playgroud)
对此:
//Bunch of code...
Run Code Online (Sandbox Code Playgroud) 我正在忙着一个脚本,它会在我的网站上制作一个带有多个标记的谷歌地图画布.我希望当你点击一个标记时,会打开一个信息窗口.我已经这样做了,代码就是这样:
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
function addMarker(map, address, title) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:title
});
google.maps.event.addListener(marker, 'click', function() {
var infowindow = new google.maps.InfoWindow();
infowindow.setContent('<strong>'+title + '</strong><br />' + address);
infowindow.open(map, marker);
});
} else {
alert("Geocode was …Run Code Online (Sandbox Code Playgroud)