Jump to content

php, mysql, javascript, and google map!


php_novice2007

Recommended Posts

Hi, I'm trying to use php code to read some longitudes and latitudes and then plot them on google map.

 

Heres my code:

 

<?php
  // establish link
  $username="root";
  $password="abcd";
  $database="red1";
  $dbtable = $u0100;
  $link=mysql_connect("localhost", $username, $password) or die("Cannot connect to database");
  
  //select database
  @mysql_select_db($database) or die("Unable to select database");
  	
  //The whole contents of $dbtable from the red1 database is now contained in $result.
  $query="SELECT * FROM ".$dbtable;
  $result=mysql_query($query, $link) or die("Unable to load selected table");
  
  //find out how many rows there are in the database
  $num=mysql_num_rows($result) or die("There are no results");
    
  //close link
  mysql_close($link) or die("Unable to close database");

  $lat = array();
  $long = array();
  $i = 0;
  while ($i<$num) {
    $lat[$i]=mysql_result($result,$i,"lat");
  	$long[$i]=mysql_result($result,$i,"lng");
    $i++;
  }
?>  

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Track Example</title>

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA_ZKXKLNCYSzHFMNyG-Bj2xQXwYfUv9Mi5KFTosg"
      type="text/javascript"></script>
    <script type="text/javascript">

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
  	map.addControl(new GSmallMapControl());
  	map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(<?php echo $lat[0]; ?>, <?php echo $long[0]; ?>), 13);
  var points = [];
<?php  	
    for ($i=1;$i<count($lat);$i++) {
      echo "points.push(new GLatLng($lat[$i],$long[$i]));";
    }
?>
    map.addOverlay(new GPolyline(points));
}
}
</script>

  </head>
  <body onload="load()" onunload="GUnload()"   text="#E76300" link="#E76300">
    <div id="map" style="width: 500px; height: 300px"></div>

    <font style="color:#E76300; font-family: courier;">
    <br />

  </body>
</html>

 

My problem is when I try to load the page I get this pop up which says:

 

"A script on this page is causing mozilla to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

 

If I click "ok", it keeps popping up again, if I click "cancel", I get a map being loaded, but no track on it..

 

Is there something wrong with my script? There are currently 453 points that I want to plot (this number is growing though...)

 

Another question: How can I define the size of the map generated? I read the API and it says that I can add in a width and height, so I just added in two numbers like   

 

var map = new GMap2(document.getElementById("map"),20,50);

 

this doesnt seem to work... I don't think I'm using it correctly :(

 

Thanks!!

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.