Phi*_*ötz 3 google-maps zoom google-maps-api-3
我有一个问题我是谷歌地图的初学者,并不是很好的Java脚本,但在PHP.是否存在"自动缩放"功能的可能性解决方案.我在地图上有不同的标记,我想将自动缩放到每个标记为Visibel的级别吗?
有没有解决方案请帮帮我!
好的这是我的脚本:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCxuRdCmN2BO5PD7kwI0mO8JflcUOF4CtI&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(50.903033, 10.496063),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var markerBounds = new google.maps.LatLngBounds();
var contentString;
<? php
$i = 1;
foreach($FertigID as $ID) {
$result = mysql_query("SELECT * FROM Daten_CH WHERE ID = ".$ID."");
while ($Ergebnisse = mysql_fetch_array($result)) { // Werden alle ergebnisse (ID´s) in einen Array geschriebenn
if (isset($Ergebnisse["GIS_y"]) && $Ergebnisse["GIS_y"] != "" && $Ergebnisse["GIS_y"] != " ") { ?> contentString = '<a href="Change.php?ID=<?php echo $ID; ?>"><input type="button" value="BEARBEITEN"></button></a>';
var Position = new google.maps.LatLng( <? php echo $Ergebnisse["GIS_y"]; ?> , <? php echo $Ergebnisse["GIS_x"]; ?> );
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker <? php echo $i; ?> = new google.maps.Marker({
position: Position,
map: map,
title: '<?php echo $Ergebnisse["AA_Objektname"]; ?>'
});
google.maps.event.addListener(marker <? php echo $i; ?> , 'click', function() {
infowindow.open(map, marker <? php echo $i; ?> );
});
<? php
}
}
$i++;
} ?>
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Run Code Online (Sandbox Code Playgroud)
你想要做的是创建一个LatLngBounds对象,使用它的extend方法用你的标记扩展边界(使用LatLng对象),然后使用Map对象的fitBounds(或者panToBounds你想要的动画),地图将自动缩放到一个它将显示所有标记的位置.
这是一些基本的伪代码:
// You create your map. You have to do this anyway :)
// The Map object has a lot of options, you specify them according to your needs.
var map = new google.maps.Map(document.getElementById('map'), {
'param1': 'value1',
'param2': 'value2'
});
// Create a new LatLngBounds object
var markerBounds = new google.maps.LatLngBounds();
// Add your points to the LatLngBounds object.
foreach(marker in markers) {
var point = new google.maps.LatLng(marker.lat, marker.lng);
markerBounds.extend(point);
}
// Then you just call the fitBounds method and the Maps widget does all rest.
map.fitBounds(markerBounds);
Run Code Online (Sandbox Code Playgroud)
这是你的代码:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCxuRdCmN2BO5PD7kwI0mO8JflcUOF4CtI&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(50.903033, 10.496063),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var markerBounds = new google.maps.LatLngBounds();
var contentString;
<? php
$i = 1;
foreach($FertigID as $ID) {
$result = mysql_query("SELECT * FROM Daten_CH WHERE ID = ".$ID."");
while ($Ergebnisse = mysql_fetch_array($result)) { // Werden alle ergebnisse (ID´s) in einen Array geschriebenn
if (isset($Ergebnisse["GIS_y"]) && $Ergebnisse["GIS_y"] != "" && $Ergebnisse["GIS_y"] != " ") { ?> contentString = '<a href="Change.php?ID=<?php echo $ID; ?>"><input type="button" value="BEARBEITEN"></button></a>';
var Position = new google.maps.LatLng( <? php echo $Ergebnisse["GIS_y"]; ?> , <? php echo $Ergebnisse["GIS_x"]; ?> );
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker <? php echo $i; ?> = new google.maps.Marker({
position: Position,
map: map,
title: '<?php echo $Ergebnisse["AA_Objektname"]; ?>'
});
markerBounds.extend(Position); // you call this method for each Position (LatLng object)
google.maps.event.addListener(marker <? php echo $i; ?> , 'click', function() {
infowindow.open(map, marker <? php echo $i; ?> );
});
<? php
}
}
$i++;
} ?>
map.fitBounds(markerBounds); // Then you call this method here.
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7655 次 |
| 最近记录: |