我的 Google Maps v3 代码有问题。它一直以一个点为中心,根本不会让我缩放或真正玩地图。即使您单击地图上的某个绘图点,它也会快速调整到地图的中心。所以基本上你可以缩放或使用地图上的绘图点。我在这里先向您的帮助表示感谢。
网站: 有问题的网站
代码:
$(document).ready(function(e) {
initialize();
});
var map = null;
var markersArray = [];
var markers = [];
var openedInfoWindow ="";
var geocoder = new google.maps.Geocoder();
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapInfoManual"),
mapOptions);
addMarker();
}
function addMarker() {
var bounds = new google.maps.LatLngBounds();
for(i=0; i<markersArray.length; i++)
{
CodeAddress(markersArray[i]['address']);
}
setInterval(function()
{
for(i=0; i<markers.length; i++)
{
var point = new google.maps.LatLng(markers[i]['lat'], markers[i] ['lng']);
var marker = new google.maps.Marker({
position: point,
map: map
});
bounds.extend(point);
openInfoWindow(marker,markersArray[i]['address'])
}
map.fitBounds(bounds);
},1000);
}
// Address To Marker
function CodeAddress(address)
{
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
markers.push({
'lat':lat,
'lng':lng,
'address':address
});
}
});
}
//Info Window
function openInfoWindow(marker,content)
{
var infowindow = new google.maps.InfoWindow({
content: '<div><p style=" color: #000000; font-size: 11px;">'+content+'</p> </div>'
});
google.maps.event.addListener(marker, 'click', function() {
if(openedInfoWindow !="")
{
openedInfoWindow.close()
}
infowindow.open(map,marker);
openedInfoWindow = infowindow;
});
}