Hello all,

I have created a Postgres/Postgis database where I store the limits of
my home town neighbourhoods. A simple register looks like this:

gis=# SELECT astext(limites) as limite FROM bairros WHERE
nome='TESTE';
 
limite
--------------------------------------------------------------------------------------------------------------------------
 POLYGON((-29.469492 -51.977177,-29.461422 -51.985847,-29.456638
-51.976147,-29.460749 -51.969109,-29.469492 -51.977177))
(1 registro)

Then I wrote a very simple PHP program which does some string magic,
so I get this select in an XML format:

require("conecta.php"); // get conection data
$connection = pg_connect("host=$host dbname=$database user=$username
password=$password");
if (!$connection) {
  die("Impossivel conectar : " . psql_error());
}
$query = sprintf("SELECT astext(limites) as limite FROM bairros WHERE
nome='TESTE'");
$result = pg_query($query);
if (!$result) {
 die('Busca invalida: ' . psql_error());
}

header("Content-type: text/xml");

while ($row = @pg_fetch_assoc($result)){
$resultado=$row[limite];
$resultado=str_replace("))",")]",$resultado);
$resultado=str_replace(",","<br>",$resultado);
$resultado=str_replace(" ",",",$resultado);
$resultado=str_replace("POLYGON(","[new GLatLng",$resultado);
$resultado=str_replace("<br>","), new GLatLng(",$resultado);
$resultado="<markers><marker bairro=\"".$resultado."\" /></markers>";
echo $resultado;
}
?>

Note: the replaces could be done in an easier way, I left like this
for debugging...

The output of this program is:

<markers><marker bairro="[new GLatLng(-29.469492,-51.977177), new
GLatLng(-29.461422,-51.985847), new GLatLng(-29.456638,-51.976147),
new GLatLng(-29.460749,-51.969109), new
GLatLng(-29.469492,-51.977177)]" /></markers>


So, I have this in my program:

var map;
(...)
    function load() {
      if (GBrowserIsCompatible()) {
        //cria a variável map instanciando a classe GMap2
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(-29.459796, -51.977799),14);
(...)
      loadBairros();
(...)
function loadBairros(){
        GDownloadUrl("poli_xml.php"+"?NoCache="+escape(Date()),
function(data) {
          var xml = GXml.parse(data);
          var markers =
xml.documentElement.getElementsByTagName("marker");^M
          for (var i = 0; i < markers.length; i++) {
            var bairro = markers[i].getAttribute("bairro");
            var polygon = new GPolygon(bairro, null, 3, 0.7,
"#cccccc", 0.5 );
            map.addOverlay(polygon);
         }//for
        });//GDownloadUrl

This doesn't work.

If I replace var bairro with:

var bairro = [new GLatLng(-29.469492,-51.977177), new
GLatLng(-29.461422,-51.985847), new GLatLng(-29.456638,-51.976147),
new GLatLng(-29.460749,-51.969109), new
GLatLng(-29.469492,-51.977177)];

It works. So I am doing something wrong when parsing the xml document.
I use this kind of thing with my markers, following several examples
given here and all works fine. I just am not able to find what I am
doing wrong with this polygon.

Any help is welcome!

Thanks,

Joice

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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