我正在使用谷歌地图应用程序开发一个网页,但我遇到了一些麻烦。就目前而言,网页有一个功能地图(没有任何图层)和一个搜索栏。我是编程新手,所以希望有一个我缺少的快速修复。当我搜索地址时,地图上会放置一个地标。但是,地图不会放大地标。如何为每个搜索到的地址放大地图?
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder ();
var latlng = new google.maps.LatLng (55.1667, -114.4000);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
function codeAddress () {
var address = document.getElementById ("address").value;
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);
}
});
}
</script>
谢谢