Thanks Andrew, my question really lack further elaboration. It actualy
starts with this thread (the one you helped with):

http://groups.google.com.br/group/Google-Maps-API/browse_thread/thread/64576aa2c12d326e/518866dcb823ba6e?lnk=gst&q=fighting#518866dcb823ba6e

I decided to start a new one so I could separate the issues. What I
want is to get the data out of Postgres/Postgis into a Google Maps Api
polygon. I was able to do some string magic with PHP in order to get
the array of GLatLng with a test polygon. Here is just the code
snippet:

The PostgreSQL output:

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))

I get this into a PHP code (file poli_xml.php):

$query = sprintf("SELECT astext(limites) as limite FROM bairros WHERE
nome='TESTE'");

(...)

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;

And this goes into my JavaScript:

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 = eval(markers[i].getAttribute("bairro")); //
thanks to Andrew Leach
            var polygon = new GPolygon(bairro, null, 3, 0.7,
"#cccccc", 0.5 );
            map.addOverlay(polygon);
         }//for
        });//GDownloadUrl

Problem is shp2pgsql and Google Maps work with the coordinates in a
reversed way (if only there was a GLngLat replacement...).

I could parse the array and reverse the vectors (switching latitude
and longitude). However, I believe I am not the first one to incur in
this problem. So, I decided to ask first.

Again, 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