mkaplan

PHP5 google maps example

Aug 13th, 2011
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. <?php
  2. $dbname            ='testgooglemaps'; //Name of the database
  3. $dbuser            ='root'; //Username for the db
  4. $dbpass            =''; //Password for the db
  5. $dbserver          ='localhost'; //Name of the mysql server
  6.  
  7. $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
  8. mysql_select_db("$dbname") or die(mysql_error());
  9. ?>
  10. <html>
  11.  <head>
  12.  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  13.  <title>Google Map API V3 with markers</title>
  14.  <style type="text/css">
  15.  body { font: normal 10pt Helvetica, Arial; }
  16.  #map { width: 640px; height: 480px; border: 0px; padding: 0px; }
  17.  </style>
  18.  <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
  19.  <script type="text/javascript">
  20.  //Sample code written by August Li
  21.  var blue_icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
  22.      new google.maps.Size(32, 32), new google.maps.Point(0, 0),
  23.      new google.maps.Point(16, 32)
  24.  );
  25.   var red_icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/red.png",
  26.      new google.maps.Size(32, 32), new google.maps.Point(0, 0),
  27.      new google.maps.Point(16, 32)
  28.  );
  29.  var center = null;
  30.  var map = null;
  31.  var currentPopup;
  32.  var bounds = new google.maps.LatLngBounds();
  33.  function addMarker(lat, lng, info, complete) {
  34.      var pt = new google.maps.LatLng(lat, lng);
  35.      bounds.extend(pt);
  36.      var marker = null;
  37.      if( complete == 0 ){
  38.           marker = new google.maps.Marker({
  39.              position: pt,
  40.              icon: blue_icon,
  41.              map: map
  42.          });
  43.     }
  44.     else{
  45.         marker = new google.maps.Marker({
  46.              position: pt,
  47.              icon: red_icon,
  48.              map: map
  49.          });
  50.     }
  51.      var popup = new google.maps.InfoWindow({
  52.          content: info,
  53.          maxWidth: 300
  54.      });
  55.     google.maps.event.addListener(marker, "click", function() {
  56.          if (currentPopup != null) {
  57.              currentPopup.close();
  58.              currentPopup = null;
  59.          }
  60.          popup.open(map, marker);
  61.          currentPopup = popup;
  62.     });
  63.      google.maps.event.addListener(popup, "closeclick", function() {
  64.      map.panTo(center);
  65.      currentPopup = null;
  66.      });
  67. }
  68.  function initMap() {
  69.      map = new google.maps.Map(document.getElementById("map"), {
  70.          center: new google.maps.LatLng(0, 0),
  71.          zoom: 14,
  72.          mapTypeId: google.maps.MapTypeId.ROADMAP,
  73.          mapTypeControl: false,
  74.          mapTypeControlOptions: {
  75.             style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
  76.          },
  77.          navigationControl: true,
  78.          navigationControlOptions: {
  79.             style: google.maps.NavigationControlStyle.SMALL
  80.         }
  81.     });
  82.      <?php
  83.      $query = mysql_query("SELECT * FROM poi_example");
  84.      while ($row = mysql_fetch_array($query)){
  85.          $name=$row['name'];
  86.          $lat=$row['lat'];
  87.          $lon=$row['lon'];
  88.          $desc=$row['desc'];
  89.          $complete = $row['complete'];
  90.          echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc', $complete );\n");
  91.      }
  92.      ?>
  93.      center = bounds.getCenter();
  94.      map.fitBounds(bounds);
  95.  
  96.  }
  97.  </script>
  98.  </head>
  99.  <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
  100.  <div id="map"></div>
  101.  </html>
Add Comment
Please, Sign In to add comment