【发布时间】:2013-12-26 12:15:28
【问题描述】:
我使用以下代码:
var geocoder;
var map;
var markers = [];
function initialize() {
geocoder = new google.maps.Geocoder();
// var latlng = new google.maps.LatLng(51.733833,0.351563);
var latlng = new google.maps.LatLng(53.590875,-2.279663);
// var latlng = new Array (new google.maps.LatLng (52.537,-2.061), new google.maps.LatLng (52.564,-2.017));
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
addPostCode('EX4 5SP');
addPostCode('EX16 6LH');
addPostCode('M1 2AP');
}
我找到了一些示例如何实现这一点 在以下代码中:Google MAP API v3: Center & Zoom on displayed markers 实现这一点,使用以下代码。
// map: an instance of GMap3
// latlng: an array of instances of GLatLng
var latlngbounds = new google.maps.LatLngBounds();
latlng.each(function(n){
latlngbounds.extend(n);
});
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
问题是我需要使用邮政编码在地图上显示位置。是否可以从邮政编码创建一个 GLatLng 实例数组,然后使用上面的代码在地图上缩放和居中多个标记?
【问题讨论】:
-
GLatLng 来自 Google Maps API v2,而不是 v3。你的意思是我希望的一组 google.maps.LatLng 实例?
标签: javascript google-maps google-maps-api-3