这是我所做的代码。 在我的数据库中,我有两个分支。我如何将它们放入一张地图?
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&
key=ABQIAAAAJR13WIBSSRZUvST7tS5gBBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ-gJDV6NvNYE3vFNvh-vuWPRZ0KA" type="text/javascript"></script>
<?php
include "dbconfig.inc.php";
$link = mysqli_connect("localhost","root","","sally_hairstyling");
if(!$link){
die(mysqli_error($link));}
//get all branches
$sql = "SELECT * FROM branches";
$result = mysqli_query($link,$sql);
$branch_no = 1;
while($row=mysqli_fetch_array($result)){
echo'
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng('.$row["longitude"].', '.$row["latitude"].'), 11);
map.setUIToDefault();
//branch
var branch = new GMarker(new GLatLng('.$row["longitude"].', '.$row["latitude"].'),13);
map.addOverlay(branch);
GEvent.addListener(orchard, "click", function() {
orchard.openInfoWindowHtml("<p>Here is Orchard</p>")});
}
}
</script>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
';
}
?>
答案 0 :(得分:1)
问题是你如何将每个分支回显到HTML页面。
您需要更改PHP页面
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&
key=ABQIAAAAJR13WIBSSRZUvST7tS5gBBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ-gJDV6NvNYE3vFNvh-vuWPRZ0KA" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng('.$row["longitude"].', '.$row["latitude"].'), 11);
map.setUIToDefault();
<?php
include "dbconfig.inc.php";
$link = mysqli_connect("localhost","root","","sally_hairstyling");
if(!$link){
die(mysqli_error($link));}
//get all branches
$sql = "SELECT * FROM branches";
$result = mysqli_query($link,$sql);
$branch_no = 1;
while($row=mysqli_fetch_array($result)){
echo'
//branch
var branch = new GMarker(new GLatLng('.$row["longitude"].', '.$row["latitude"].'),13);
map.addOverlay(branch);
GEvent.addListener(orchard, "click", function() {
orchard.openInfoWindowHtml("<p>Here is Orchard</p>")});
';
}
?>
}
}
</script>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>