1
我已经得到了下面的代码,它将4张地图放在一个页面上,并且根据地址为每个地图添加一个标记。但我需要映射到标记的中心。谷歌地图标记上的api中心
<script type="text/javascript">
var geocoder;
var map0,map1,map2,map3;
var markers = [];
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map0 = new google.maps.Map(document.getElementById("map_canvas1"), mapOptions);
addPostCode('@address1',map0);
map1 = new google.maps.Map(document.getElementById("map_canvas2"), mapOptions);
addPostCode('@address2',map1);
map2 = new google.maps.Map(document.getElementById("map_canvas3"), mapOptions);
addPostCode('@address3',map2);
map3 = new google.maps.Map(document.getElementById("map_canvas4"), mapOptions);
addPostCode('@address4',map3);
}
function addPostCode(address,map) {
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,
center: results[0].geometry.location,
name: address
});
markers.push(marker);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
完全不知道在哪里,使其集中在标记该地图。
这条线对标记没有意义:'center:results [0] .geometry.location,' - 标记没有'中心',仅仅是一个位置 – duncan 2013-03-14 15:41:55