我正在将 Google Maps 实施到一个新项目中,并且一页应该返回加拿大的大 (100% * 100%) 地图。我还使用地理编码来确定要传递给地图的 latlng。
这是代码:
var myLatlng = new google.maps.LatLng(37.775, -122.4183333);
var myOptions ={
zoom: 5,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var address = "Canada";
var geocoder = new google.maps.Geocoder(address);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//map.setCenter(results[0].geometry.location);
//The above was too far north
map.fitBounds(results[0].geometry.viewport);
map.setZoom(5);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
它工作得很好,只是它“向左有点太远了”。从本质上讲,它切断了大部分海洋省份。可以在这里看到一个例子:
http://50.28.69.176/~sequoia/locations.php
任何人都知道如何巧妙地解决这个问题,以便国家更好地集中在视口中?
谢谢你的帮助。