0
我一直在试图在谷歌地图上适合我的标记。 我一直尝试使用以下命令:适合谷歌地图上的标记
map.fitBounds(latlngbounds);
我无法弄清楚如何实现这一点。如何轻松添加?
到目前为止,我有以下代码波纹管:
<script type="text/javascript">
var locations = <?php echo json_encode($js_array);?>;
var lats = <?php echo json_encode($lats);?>;
var lats = <?php echo json_encode($iphoto);?>;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
console.log(locations[i].lat);
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i].latitude, locations[i].longitude),
map: map,
animation: google.maps.Animation.DROP,
icon: {size: new google.maps.Size(30, 30),
scaledSize: new google.maps.Size(30, 30),
url: locations[i].iprofilephoto,}
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent("<div><img style='width:40px;height:40px' src='"+locations[i].iprofilephoto+"'>"+locations[i].name+"</div><div><img style='width:100px;height:100px' src='"+locations[i].iphoto+"'></div>");
infowindow.open(map, marker);
}
})(marker, i));
}
看看这里了解如何使用的LatLngBounds一个例子:https://github.com/vasilionjea/jqDirect/blob/master/jqDirect.js#L23这里:https://github.com /vasilionjea/jqDirect/blob/master/jqDirect.js#L126 – istos 2014-10-29 07:47:33