我发现了怎么做..这是我的最终代码..谢谢:)大家..
<!DOCTYPE html>
<html>
<?php
include_once("config.php");
?>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
width: 500px;
height: 500px;
left;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
//var bounds;
function addRectangle(lat1, lon1, lat2, lon2)
{
var Bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(lat1, lon1),
new google.maps.LatLng(lat2, lon2)
);
var rectangle = new google.maps.Rectangle({
bounds: Bounds,
//draggable: true,
//editable: true,
map : map,
});
//rectangle.setMap(map);
}
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(44.490, -78.649),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
<?php // loading rectangles from database
$dbname ='zone'; //Name of the database
$dbuser ='root'; //Username for the db
$dbpass =''; //Password for the db
$dbserver ='localhost'; //Name of the mysql server
$dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db($dbname) or die(mysql_error());
$query = mysql_query("SELECT * FROM ville");
while ($row = mysql_fetch_array($query))
{
$name=$row['NOM_VILLE'];
$lat1=$row['LATITUDE1_V'];
$lon1=$row['LONGITUDE1_V'];
$lat2=$row['LATITUDE2_V'];
$lon2=$row['LONGITUDE2_V'];
echo "addRectangle($lat1, $lon1, $lat2, $lon2);";
}
?>
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<?php // loading makers from database
$dbname ='zone'; //Name of the database
$dbuser ='root'; //Username for the db
$dbpass =''; //Password for the db
$dbserver ='localhost'; //Name of the mysql server
$dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db($dbname) or die(mysql_error());
$query = mysql_query("SELECT * FROM ville");
while ($row = mysql_fetch_array($query))
{
$name=$row['NOM_VILLE'];
$lat1=$row['LATITUDE1_V'];
$lon1=$row['LONGITUDE1_V'];
$lat2=$row['LATITUDE2_V'];
$lon2=$row['LONGITUDE2_V'];
//$desc=$row['zone'];
echo " ".$lat1.", ".$lon1.",".$lat2.", ".$lon2."";
//echo "addMarker($lat, $lon,'<b>$name</b><br/>$desc');";
}
?>
</body>
</html>