2011-11-01 87 views
2

嗯,我有几个问题让谷歌地图使用v3 API工作。谷歌地图缩放和描述对话框不能正常工作

看看这里:[通过海报删除]

两个图,实际上,工作,但缩放级别好像它是随机的。初始化地图时,缩放设置为12。此外,如果您单击标记,说明框缺少角落并且无法关闭。下面是我使用激活这些地图的JavaScript功能:通过刚才removeing

body img { 
max-width: 520px !important; 
height: auto !important;} 

从样式表

var mapHash = []; 
var bound = new google.maps.LatLngBounds(); 
finishedCoding = false; 
function initMap(map_container_div,lat,lng) { 
    var latlng = new google.maps.LatLng(lat,lng); 
    var myOptions = { 
     zoom:12, 
     center:latlng, 
     mapTypeId:google.maps.MapTypeId.ROADMAP, 
     streetViewControl: false 
    }; 

    var map = new google.maps.Map(document.getElementById(map_container_div), myOptions); 
    if (!getMap(map_container_div)) { 
     var mapInfo = { 
      mapkey:'', 
      map:'', 
      geocoder : new google.maps.Geocoder() 
     }; 
     mapInfo.map = map; 
     mapInfo.geocoder = new google.maps.Geocoder(); 
     mapInfo.mapKey = map_container_div; 
     mapHash.push(mapInfo); 
    } 
} 

function placeMarker(myAddress, mapId, description, title) { 
    mapIndex = getMap(mapId) 
    //alert(myAddress + mapId + map) 
    mapHash[mapIndex].geocoder.geocode({ 
     'address':myAddress 
    }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      mapIndex = getMap(mapId) 
      var marker = new google.maps.Marker({ 
       map:mapHash[mapIndex].map, 
       position:results[0].geometry.location, 
       title: title 
      }); 
      bound.extend(results[0].geometry.location); 
      mapHash[mapIndex].map.fitBounds(bound); 

      finishedCoding = true; 
      placeDesc(marker,description,mapId); 

     } 
    }); 
} 

function placeDesc(marker,myDesc,mapId) { 
    mapIndex = getMap(mapId); 
    var infowindow = new google.maps.InfoWindow({ 
     content: myDesc 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.open(mapHash[mapIndex],marker); 
    }); 
} 

function getMap(mapKey) { 
    for (var i = 0 ; i < mapHash.length ; i++) { 
     if (mapHash[i].mapKey == mapKey) { 
      return i; 
     } 
    } 
    return false; 
} 

function startmap(mapidd,address,description,title,lat,lng) { 
    initMap(mapidd,lat,lng) 
    placeMarker(address,mapidd,description,title) 
} 

回答

0

我自己解决了这个问题,并且正在踢我自己没有想到这一点。 :)

就不得不添加mapHash[mapIndex].map.setZoom(12);

我删除了以下2个代码:

bound.extend(results[0].geometry.location); 
mapHash[mapIndex].map.fitBounds(bound); 
2
+0

这实际上没有区别。 =/ – Jared

+0

其实我只是发送你的解决方案 “说明框缺少角落,无法关闭。” 并获得放置setZoom选项。如果你再次放置该样式表,那么你观察与描述框相同的问题。 –

+0

嗯你是对的,这确实解决了角落问题,但由于某些原因,点击x时对话框仍然不会关闭。与我需要的setZoom函数相比,这并没有什么大不了的。谢谢你。 – Jared

1

你的对话框都不会因为一个JavaScript错误的关闭。 点击监听器中的infowindow.open(mapHash[mapIndex],marker);有些问题。它显示窗口,这让你认为错误发生后,但我很确定它是在呼叫本身。当我调试你没有犯一个明显的错误,但我仍然认为这一行代码是罪魁祸首。