我在 Zurb Foundation 页面上有一个使用版本 3 API 生成的动态谷歌地图。地图完美运行,一切都很好,除了地图没有响应。
请注意,我无法使用 iframe 解决方案,因为我正在使用 php api 调用获取页面加载时的标记和信息窗口数据。
如何使用 zurb Foundation 3 使此地图响应访问者的视口?
我使用 PHP 动态打印 javascript 函数来生成地图。这是功能。
public function printgoogle(){
//Irrelevant code
$jsarr = array();
$jsarr = json_encode($phparray);
print "<script>";
print "function initialize(){";
print "var mapProp = {";
print "center:new google.maps.LatLng(".$this->centerlat.",".$this->centerlng."),";
print "zoom:".$this->mainzoom.",";
print "mapTypeId:google.maps.MapTypeId.ROADMAP";
print "};";
print "var map=new google.maps.Map(document.getElementById(\"map-canvas\"),mapProp);";
print "var infowindow = new google.maps.InfoWindow();";
print "var locations = $jsarr;";
print "var marker, i;";
print "for (i = 0; i < locations.length; i++) {";
print "marker = new google.maps.Marker({";
print "position: new google.maps.LatLng(locations[i][1], locations[i][2]),";
print "map: map";
print "});";
print "google.maps.event.addListener(marker, 'click', (function(marker, i) {";
print "return function() {";
print "infowindow.setContent(locations[i][0]);";
print "var pos = marker.getPosition();";
print "infowindow.setPosition(pos);";
print "infowindow.open(map, marker);";
print "}";
print "})(marker, i));";
print "}";
print "}";
print "google.maps.event.addDomListener(window, 'load', initialize);";
print "</script>";
}
这是HTML
<div class="row" id="2a1">
<div class="twelve columns" id="2a1a">
<div id="map-canvas"></div>
</div>
</div>