如何編輯以下代碼以將函數初始化和codeAddress合併爲一個?結合兩個JavaScript函數一個接一個地運行?
{literal}
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = "{/literal}{$listing.City}, {$listing.State}{literal}";
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({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
{/literal}
</script>
在此先感謝
也有作品。謝謝 – Anthony 2011-01-30 00:49:52
感謝您的投票。 – 2011-01-30 01:00:29