Google maps 谷歌地图标记API-初始化中心
我正在运行一段代码来显示一组API标记。使用我的代码可以很好地工作,但中心根据我的标记进行自我调整。我想预设中心和缩放因子。我知道我必须在Google maps 谷歌地图标记API-初始化中心,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在运行一段代码来显示一组API标记。使用我的代码可以很好地工作,但中心根据我的标记进行自我调整。我想预设中心和缩放因子。我知道我必须在“function initialize()”中添加一些代码,可能类似于: var mapOptions = { zoom: 7, center: new google.maps.LatLng(9.22316, 52.35308) 但是如果我在运行的代码中复制,它就不再工作了。所以请你帮我一下,告诉我我需要修改代码的哪一部分 以下是我的运行代码: <!
“function initialize()”
中添加一些代码,可能类似于:
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>
简单地图
html,正文,#地图画布{
身高:100%;
边际:0px;
填充:0px
}
var映射;
var LocationData=[xxx,yyy,zzz,0];
变量iconURLPrefix=http://maps.google.com/mapfiles/ms/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+“黄点.png”
]
函数初始化()
{
变量映射=
新的google.maps.Map(document.getElementById('Map-canvas');
var bounds=new google.maps.LatLngBounds();
var infowindow=new google.maps.infowindow();
对于(LocationData中的var i)
{
var p=位置数据[i];
var latlng=new google.maps.latlng(p[0],p[1]);
边界扩展(latlng);
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
图标:图标[p[3]],
标题:p[2]
});
google.maps.event.addListener(标记'click',函数(){
infowindow.setContent(this.title);
打开(地图,这个);
});
}
映射边界(bounds);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
非常感谢你的帮助 删除对:
map.fitBounds(bounds)的调用代码>
然后,如中所述,添加预定义的缩放和居中:
var映射;
函数初始化(){
变量映射选项={
缩放:7,
中心:新google.maps.LatLng(9.2231652.35308)
};
变量映射=
新的google.maps.Map(document.getElementById('Map-canvas')、mapOptions);
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}
一开始我忘了打招呼;)