Now I am having a similar but slightly different problem:

I'm again retrieving a polygon from my database, from a different
table in the database. This time it zooms in on where the polygon
should be... there just isn't anything there. I thought that perhaps
it needed some styling information (line and fill colors, widths, and
transparencies) so I added that in. It didn't make a difference.

You can see the page with the zoom-in response here:
http://myfarms.org/test/googlemap_test.html

The php I am using is as follows:

<?php

require("seasame.php");

//dom refers to the document itself; to createElement it must be
called from dom
//node is the recently-created tag to be added to the tree
//parnode is a pointer to the current place in the DOM tree that will
be the parent of node
//newnode is a pointer to the most recently added node for the purpose
of adding attributes to it, esp. in cases of sibling nodes
//topnode is the Document node, inside of which everything must go

header("Content-Type: application/vnd.google-earth.kml
+xml;charset=UTF-8");

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("Document");
$topnode = $dom->appendChild($node);

//create styling
$node = $dom->createElement("Style");
$parnode = $topnode->appendChild($node);
$parnode->setAttribute("id", "a");
$node = $dom->createElement("LineStyle");
$parnode = $parnode->appendChild($node);
$node = $dom->createElement("color");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = "#7CFC00";
$node = $dom->createElement("width");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = "3";
$parnode = $parnode->parentNode;
$node = $dom->createElement("PolyStyle");
$parnode = $parnode->appendChild($node);
$node = $dom->createElement("color");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = "#7CFC00";
$node = $dom->createElement("outline");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = ".8";
$node = $dom->createElement("fill");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = "0";

//create Placemarks to hold polygons
$node = $dom->createElement("Placemark");
$parnode = $topnode->appendChild($node);
//apply styling:
$node = $dom->createElement("styleUrl");
$newnode = $parnode->appendChild($node);
$newnode->nodeValue = "#a";
$node = $dom->createElement("MultiGeometry");
$parnode = $parnode->appendChild($node);


//testing
$field_num = 2;


//create <Polygon>
$node = $dom->createElement("Polygon");
$parnode = $parnode->appendChild($node); //appended to MultiGeometry
//add attribute "id" set to current field
$parnode->setAttribute("id", $field_num);
//create and append other tags
$node = $dom->createElement("outerBoundaryIs");
$parnode = $parnode->appendChild($node); //appended to Polygon
$node = $dom->createElement("LinearRing");
$parnode = $parnode->appendChild($node); //appended to outerBoundaryIs
$node = $dom->createElement("coordinates");
$newnode = $parnode->appendChild($node); //appended to LinearRing

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection)
 {
   die('Not connected: ' . mysql_error());
 }

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected)
 {
   die ('Can\'t use DB: ' . mysql_error());
 }

// QUERY: Select polygon according to field
$query = "SELECT X(Field_Point), Y(Field_Point) FROM FieldPoints WHERE
Field_ID = " . $field_num . " ORDER BY Field_Point_ID";
$points = mysql_query($query);
if (!points)
 {
   die('Invalid query: ' . mysql_error());
 }

while ($row = @mysql_fetch_assoc($points))
 {
   //output the points in (lat,lang) form:
   $coords="";
   $coords .= (string)$row['Y(Field_Point)'];
   $coords .= ",";
   $coords .= (string)$row['X(Field_Point)'];
   $coords .= " ";
   $newnode->nodeValue .= $coords;
 }

echo $dom->saveXML();
?>

And it produces the following KML:

<?xml version="1.0"?>
<Document>
<Style id="a">
<LineStyle>
<color>#7CFC00</color>
<width>3</width>
</LineStyle>
<PolyStyle>
<color>#7CFC00</color>
<outline>.8</outline>
<fill>0</fill>
</PolyStyle>
</Style>

<Placemark>
<styleUrl>#a</styleUrl>
<MultiGeometry>
<Polygon id="2">
<outerBoundaryIs>
<LinearRing>
<coordinates>-85.4994099140167,40.4686202684815
-85.4983263015747,40.4685141612815 -85.4983477592468,40.4676326488315
-85.4995815753937,40.4676326488315 -85.4995493888855,40.4681795143991
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document>

This LOOKS okay, to my eyes, but it doesn't work, so there is probably
something wrong with it. Can anyone help me figure out what that is?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to