I am at the end of my rope please help:)

I have a db that has addresses I would like a google map to show a
queried address and create a marker for each address in the db on the
map.

I have tried the Using PHP and MySQL to create KML tutorial and have
created every file I was supposed to. I cannot get the map to show the
markers on the map.

Here is the google map code I have created and it shows the map of
seattle but does not show the addresses on the map with a marker.

 <script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAA_YVHg1YHvpalent78-
SSihTz2Lg5IvdPwr5sjTZ1lEkB4NZA5RQW5S9NAp-526dMo3JeAKa8Ca-s_g"
       type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

        var iconBlue = new GIcon();
    iconBlue.image = 'http://labs.google.com/ridefinder/images/
mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon();
    iconRed.image = 'http://labs.google.com/ridefinder/images/
mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["restaurant"] = iconBlue;
    customIcons["bar"] = iconRed;

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(47.614495, -122.341861), 13);

        // Change this depending on the name of your PHP file
        GDownloadUrl("phpsql_genkml3.php", function(data) {
          var xml = GXml.parse(data);
          var markers =
xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
            var address = markers[i].getAttribute("address");
            var type = markers[i].getAttribute("type");
            var point = new
GLatLng(parseFloat(markers[i].getAttribute("lat")),
 
parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, name, address, type);
            map.addOverlay(marker);
          }
        });
      }
    }

    function createMarker(point, name, address, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + name + "</b> <br/>" + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
        function load()
        {
         var map;  var geoXml;
         if (GBrowserIsCompatible())
          {
          map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());    geoXml = new
GGeoXml('http://pesttrackers.com/phpmysql_kmlnl.kml');
                   map.addOverlay(geoXml);
                    map.setCenter(new GLatLng(47.613976,-122.345467), 13);  }}
                         //]]>
  </script>
 <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px">

This is the code for the php file to echo out the kml


<?php
require('mysql_connect.php');

 // Opens a connection to a MySQL server.
$dbhost = "";
$dbusername = "";
$dbpass = "
$dbname = "";

$conn = mysql_connect($dbhost, $dbusername,$dbpass,$dbname);

        mysql_select_db($dbname);
if (! $conn)
die(mysql_error());


 // Selects all the rows in the markers table.
 $query = 'SELECT * FROM markers WHERE 1';
 $result = mysql_query($query);
 if (!$result)
 {
  die('Invalid query: ' . mysql_error());
 }

// Creates an array of strings to hold the lines of the KML file.
$kml = array('<?xml version="1.0" encoding="UTF-8"?>');
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1";>';
$kml[] = ' <Document>';
$kml[] = ' <Style id="restaurantStyle">';
$kml[] = ' <IconStyle id="restuarantIcon">';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://maps.google.com/mapfiles/kml/pal2/icon63.png</
href>';
$kml[] = ' </Icon>';
$kml[] = ' </IconStyle>';
$kml[] = ' </Style>';
$kml[] = ' <Style id="barStyle">';
$kml[] = ' <IconStyle id="barIcon">';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://maps.google.com/mapfiles/kml/pal2/icon27.png</
href>';
$kml[] = ' </Icon>';
$kml[] = ' </IconStyle>';
$kml[] = ' </Style>';

// Iterates through the rows, printing a node for each row.
while ($row = @mysql_fetch_assoc($result))
{
  $kml[] = ' <Placemark id="placemark' . $row['id'] . '">';
  $kml[] = ' <name>' . htmlentities($row['name']) . '</name>';
  $kml[] = ' <description>' . htmlentities($row['address']) . '</
description>';
  $kml[] = ' <styleUrl>#' . ($row['type']) .'Style</styleUrl>';
  $kml[] = ' <Point>';
  $kml[] = ' <coordinates>' . $row['lng'] . ','  . $row['lat'] . '</
coordinates>';
  $kml[] = ' </Point>';
  $kml[] = ' </Placemark>';

}

// End XML file
$kml[] = ' </Document>';
$kml[] = '</kml>';
$kmlOutput = join("\n", $kml);

echo $kmlOutput;
?>

I would like to know how to have the address from the database show up
on the map of that exact address. I know I have to change the co-
ordinates in the script (too what I do not know because there will be
a variance of addresses and locations) I simply need a map to show the
exact address from the db and then make a marker on the map and show
the map of the address and marker.


Is there something else I have to change in the map script to get the
map to query the db and bring back the address and display it on a map
with adding a marker. I need this map to show the location of the
selected address with the marker on the map. I have completed the
tutorial : Using PHP/MySQL with Google Maps. I have gotten that script
to work fine. (As the tutorial)The code for that is :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml";>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/
>
    <title>Google Maps AJAX + mySQL/PHP Example</title>
    <script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAA_YVHg1YHvpalent78-
SSihTz2Lg5IvdPwr5sjTZ1lEkB4NZA5RQW5S9NAp-526dMo3JeAKa8Ca-s_g"
       type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

    var iconBlue = new GIcon();
    iconBlue.image = 'http://labs.google.com/ridefinder/images/
mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon();
    iconRed.image = 'http://labs.google.com/ridefinder/images/
mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/
mm_20_shadow.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["restaurant"] = iconBlue;
    customIcons["bar"] = iconRed;

   function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(47.614495, -122.341861), 13);

   }
  }
        // Change this depending on the name of your PHP file
        GDownloadUrl("mapit.php", function(data) {
          var xml = GXml.parse(data);
          var markers =
xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
            var address = markers[i].getAttribute("address");
            var type = markers[i].getAttribute("type");
            var point = new
GLatLng(parseFloat(markers[i].getAttribute("lat")),
 
parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, name, address, type);
            map.addOverlay(marker);
          }
        });



    function createMarker(point, name, address, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + name + "</b> <br/>" + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
    //]]>
  </script>
  </head>

  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>
  </body>
</html>


and the second script to this is the script to Use PHP's echo to
output XML:






<?php
require("mysql_connect.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}

// Opens a connection to a mySQL server


// Opens a connection to a mySQL server
$dbhost = "";
$dbusername = "";
$dbpass = "
$dbname = "";

$conn = mysql_connect($dbhost, $dbusername,$dbpass,$dbname);

        mysql_select_db($dbname);
if (! $conn)
die(mysql_error());

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}



// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML('&','&', $row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>

I have been bouncing back and forth between these tutorials and trying
to read all the info about this process but cannot seem to find the
answer I am looking for to incorporate this into my website and I have
been trying to do this for so long and I would be ever so grateful for
some advice as to what I am doing wrong or what I am not doing.

I have the db set up just like in the tutorial. The file that echo's
the kml works fine it produces all the addresses and lat and lng and
all the information in the markers table. So some of these scripts to
my knowledge are working correctly.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to