-1
我正在運行顯示一堆API標記的代碼。與我的代碼一起工作良好,但中心依賴於我的標記進行自我調整。我想預設中心和縮放係數。我知道,我必須在'function initialize()'
大概就像添加一些代碼:谷歌地圖標記API - 初始化中心
var mapOptions = { zoom: 7, center: new google.maps.LatLng(9.22316, 52.35308)
但是,如果我在運行代碼複製在它不工作了。所以請你能幫助我,告訴我我需要修改哪部分代碼?
這裏是我的代碼運行:
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map;
var LocationData = [ xxx, yyy, zzz, 0];
var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/icons/';
var icons = [
iconURLPrefix + 'red-dot.png',
iconURLPrefix + 'green-dot.png',
iconURLPrefix + 'blue-dot.png',
iconURLPrefix + 'orange-dot.png',
iconURLPrefix + 'purple-dot.png',
iconURLPrefix + 'pink-dot.png',
iconURLPrefix + 'yellow-dot.png'
]
function initialize()
{
var map =
new google.maps.Map(document.getElementById('map-canvas'));
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
for (var i in LocationData)
{
var p = LocationData[i];
var latlng = new google.maps.LatLng(p[0], p[1]);
bounds.extend(latlng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon : icons[p[3]],
title: p[2]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(this.title);
infowindow.open(map, this);
});
}
map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
非常感謝您的幫助!
我忘了說你好在開始時; ) – Chillkroete1206 2015-03-02 21:51:09