开发者

How to put two branches in one google map?

This is the codes i have done. In my database, i have two branches. How do 开发者_运维知识库i put them into one map?

   <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;
   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>
    ';
 }
?>


The problem is how you're echoing each of your branches into your HTML page.

  1. You need to move the declarations of the map outside of the while loop:
  2. In your while loop you need to each only the branch code

You will need to change your PHP page

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;
   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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜