我有一个网页,其中包含具有多个标记的地图,我希望我可以找到一种方法,以便在窗口大小调整或在窗口大小时查看所有这些标记不同的视口。在调整窗口大小时在屏幕上保留Google地图标记
我已经尝试了不同的解决方案,我已经找到了这个,但它导致以各种方式破坏代码。
这里是我的代码:
function draw_map($id, $mark, $lat, $long, $zoom, $width, $height, $control, $map_type, $geo_codes) {
#intialize output
$output = '';
#put together array
// print_r($geo_codes);exit;
$output .= "
<div id='truckmap' ></div>
<script>
function initMap() {
var myLatLng = {lat: ".$lat.", lng: ".$long."};
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(document.getElementById('truckmap'), {
center: myLatLng,
scrollwheel: false,
zoom: ".$zoom."
}); ";
foreach ($geo_codes as $key => $stop) {
$output .= "
var infowindow = new google.maps.InfoWindow({
content: '".$stop['text']."'
});
var marker = new google.maps.Marker({
map: map,
position: {lat: ".$stop['latitude'].", lng: ".$stop['longitude']."},
title: '".$stop['opts']['title']."'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});";
}
$output .= "}</script><script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyCmXYC5YlrqIQXuJwfYe2xiyZjswOKxsZE&callback=initMap' async defer></script> ";
#return output
return $output;
} #end function
我的JavaScript和PHP是有限的,所以我可以使用所有的帮助下,我能得到的知识!
我怕我不明白你的答案。我没有写在这里发布的原始代码,我只知道基本的Javascipt,所以我不知道如何调整你的解决方案到我现有的代码中。 – LouiseW
试试我已经在更新中的代码,看看是否适用于您。 –
太棒了,非常感谢! :D – LouiseW