Jump to content

google map API with PHP - stalls rest of page?


mackin

Recommended Posts

Hi,

 

I am using the Google map API to display some businesses on a map - the sequence is map and below it a list of the establishments from a DB.

 

Before I put the google map in, the list of establishments in the while table loop worked correctly.

 

Now the map is there - that works, but the looping table doesnt display - I feel that it may be something to do with

 <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
    { ?> 
    new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>),

<?php  ; }  ?>

and the second fetch array -

 while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))

 

Any Advice?

 

 

<?php


// *******************************below is  bit that selects hotels based on outcode of postcode and prints table with links to details pages

$sql2 = "SELECT * FROM hotels WHERE (SUBSTRING_INDEX(est_postcode, ' ', 1))   IN ('$matches') ";

$result2 = mysql_query($sql2) or die('query failed: ' . mysql_error());
$num_rows = mysql_num_rows($result2);
echo "<p> Your search has found ".$num_rows . " establishment(s) </p>";

?>
<script type="text/javascript">



var berlin = new google.maps.LatLng(<? echo $lat2 ?>, <? echo $lng2 ?>); 


var neighborhoods = [

<?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
    { ?> 
    new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>),

<?php  ; }  ?>
];




  var markers = [];
  var iterator = 0;

  var map;

  function initialize() {
    var mapOptions = {
      zoom: 12,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: berlin
    };

    map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
  }

  function drop() {
    for (var i = 0; i < neighborhoods.length; i++) {
      setTimeout(function() {
        addMarker();
      }, i * 200);
    }
  }

  function addMarker() {
    markers.push(new google.maps.Marker({
      position: neighborhoods[iterator],
      map: map,
  title:"Hello World!",
      draggable: false,
      animation: google.maps.Animation.DROP
    }));
    iterator++;
  }
</script>

<div id="map_canvas" style="width: 614px; height: 400px;">map div</div>
<button id="drop" onclick="drop()">Drop Markers</button>


<?php 
echo "<table id ='results' border=0>";
    while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
    { 
echo "<tr>";



  echo "<td><a class='blueboldtitle' href='bandb.php?id=". $row["id"] . "'>" . ucwords(strtolower($row["est_name"])) ."</a></td><td>" . $row["est_postcode"] ."</td><td> ". $row["est_areacode"]." ". $row["est_landline"] ."</td><td><a href='bandb.php?id=". $row["id"] . "'>[More Info] </a></td>";
  	echo "</tr>";
    } 

echo "</table>";  
    
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.