1 (edited by kostas 2008-04-23 1:50:25 PM)

Topic: xajax and googlemaps

hi,
i'm trying to make googlemaps markers to load dynamicaly using xajax.

I have made a php function to load the markers and respond with xml using xajax.

the respond i take through xajax after checking a check box is the following.



<markers><marker id="3" cid="4" pid="16" lat="40.636752860719" lon="40.636752860719" locid="2" image="../modules/addresses/images/categories/cafe-bar.png" tooltip="Title2"/></markers><?xml version="1.0" encoding="iso-8859-7" ?>



which means that the ajax part works...

now i have 2 js script functions which is supposed to parse those data and show the corresponding marker on the map.

the code is the following..




function loadMarkers(locid,cid) {

xajax.request.onreadystatechange = function() {
if (xajax.request.readyState == 4) {
var xmlDoc = GXml.parse(xajax.request.responseText);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");

ii = 0;

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lon = parseFloat(markers[i].getAttribute("lon"));
var locid = parseFloat(markers[i].getAttribute("locid"));
var id = parseFloat(markers[i].getAttribute("id"));
var cid = parseFloat(markers[i].getAttribute("cid"));
var pid = parseFloat(markers[i].getAttribute("pid"));
var tooltip = markers[i].getAttribute("tooltip");
var image = markers[i].getAttribute("image");

var point = new GLatLng(lat,lon);
var marker = createMarkersVisible(point,cid,pid,lid,tooltip,image);


}

}
}

}

function createMarkersVisible(point,cid,pid,lid,tooltip,img) {
//var image=img;
var icon = new GIcon();
icon.image = img;
//icon.shadow = "";
icon.iconSize = new GSize(20, 20);
icon.shadowSize = new GSize(19, 20);
icon.iconAnchor = new GPoint(20, 19);
icon.infoWindowAnchor = new GPoint(20, 8);

// creation marker
var marker = new GMarker(point,{icon:icon, title:tooltip});

marker.cid = cid;
marker.pid = pid;
marker.lid = lid;

// The new marker "mouseover" listener -shows the tooltip
// ====== The new marker "mouseover" and "mouseout" listeners ======

//GEvent.addListener(marker,"mouseover", function() { showTooltip(marker);});

//GEvent.addListener(marker,"mouseout", function() { tooltip.style.visibility="hidden"});

GEvent.addListener(marker,"click", function() {
location.href="visit.php?cid="+marker.cid+"&lid="+marker.lid;
});

gmarkers.push(marker);

map.addOverlay(marker,icon);

return marker;
}




these two functions should show the markers but yet the markers are not showing. i suspect there is something wrong with the parsing of the data from the response.

Anybody has any suggestions or ideas?

2 (edited by kostas 2008-04-23 2:22:07 PM)

Re: xajax and googlemaps

actually the php code is not as valid as i thought! I think the problem should be there. This is the code


function markerLoader($locid,$cid){

global $xoopsDB, $xoopsModuleConfig,$myts;

if($locid==null){
$result = $xoopsDB->query("SELECT lid, cid, pid, title, lat, lon, locid FROM ".$xoopsDB->prefix("addresses_links")." where status>0 AND cid=$cid OR pid=$cid", $xoopsModuleConfig['newlinks'], 0);
}
else {
$result = $xoopsDB->query("SELECT lid, cid, pid, title, lat, lon, locid FROM ".$xoopsDB->prefix("addresses_links")." where status>0 AND locid=$locid AND cid=$cid OR pid=$cid", $xoopsModuleConfig['newlinks'], 0);

   // === First set the MIME type to XML ===
  header("Content-type: text/xml");
   $objResponse = new xajaxResponse();

  // === Always output the <markers> tag, even if passed a bad request ==
echo '<markers>';

while(list($lid, $cid, $pid, $ltitle, $lat, $lon, $locid) = $xoopsDB->fetchRow($result)) {
           
    $result2=$xoopsDB->query("SELECT imgurl FROM ".$xoopsDB->prefix("addresses_cat")." WHERE cid = $cid ORDER BY title") or exit("Error");
        while($image = $xoopsDB->fetchArray($result2)) {
                    $limage=$image['imgurl'];
                    $limage=XOOPS_URL.$limage;
                }
echo '<marker id="'.$lid.'" cid="'.$cid.'" pid="'.$pid.'" lat="'.$lat.'" lon="'.$lat.'" locid="'.$locid.'" image="'.$limage.'" tooltip="'.$myts->makeTboxData4Show($ltitle).'"/>';
 
}

// === Always output the </markers> tag, even if passed a bad request ==
  echo '</markers>';
  return $objResponse;
}

and this is the response i get


Wed Apr 23 2008 16:14:35 GMT+0300

ERROR: ResponseReceived: Invalid response XML: The response contains an unexpected tag or text: {data}.

Wed Apr 23 2008 16:14:35 GMT+0300

RECEIVED [status: 200, size: 660 bytes, time: 1017ms]:
<markers><marker id="2" cid="24" pid="0" lat="37.973297119866" lon="37.973297119866" locid="1" image="http://www.guidemap.gr/modules/addresses/images/categories/accomodation.png" tooltip="??????"/><marker id="12" cid="24" pid="0" lat="40.6579828211446" lon="40.6579828211446" locid="2" image="http://www.guidemap.gr/modules/addresses/images/categories/accomodation.png" tooltip="exedoros"/><marker id="13" cid="25" pid="24" lat="39.5460685850664" lon="39.5460685850664" locid="3" image="http://www.guidemap.gr/modules/addresses/images/categories/enikiazomena.png" tooltip="Skevoulis Studios"/></markers><?xml version="1.0" encoding="iso-8859-7" ?>
<xjx>
</xjx>

Re: xajax and googlemaps

i now get a proper response from the server, my question is how can i parse the data from it! the function i'm using is the following

     function loadMarkers(locid,cid) {
       
        xajax.request.onreadystatechange = function() {
          if (xajax.request.readyState == 4) {
            var xmlDoc = XML.newDocument();
            xmlDoc.loadXML(xajax.request.responseText);
            xmlDoc = GXml.parse(xmlDoc);           
            //xmlDoc = GXml.parse(xajax.request.responseText);
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
             alert("ok");       
            ii = 0;

            for (var i = 0; i < markers.length; i++) {
              // obtain the attribues of each marker
                var lat = parseFloat(markers[i].getAttribute("lat"));
                var lon = parseFloat(markers[i].getAttribute("lon"));
                var locid = parseFloat(markers[i].getAttribute("locid"));
                var id = parseFloat(markers[i].getAttribute("id"));
                var cid = parseFloat(markers[i].getAttribute("cid"));
                var pid = parseFloat(markers[i].getAttribute("pid"));
                var tooltip = markers[i].getAttribute("tooltip");
                var image = markers[i].getAttribute("image");
                          
                var point = new GLatLng(lat,lon);
                var marker = createMarkersVisible(point,cid,pid,lid,tooltip,image);
             
            }
          }
        }
     
      }
      


as you can see there i have included an alert box in  if (xajax.request.readyState == 4) but this is never shown! what is the problem there? anybody ??

Re: xajax and googlemaps

hi i wrote a php function that gives me a responce of the markers information in the following format.

<?xml version="1.0" encoding="iso-8859-7" ?>
<xjx><xjxrv>
<![CDATA[
<markers>
<marker id="3" cid="4" pid="16" lat="40.636752860719" lon="40.636752860719" locid="2" image="cafe-bar.png" tooltip="Title2"></marker>
</markers>]]>
</xjxrv>
</xjx>


I call the php function through js! can anybody tell me how to parse those data (the responce) through js! ??? Please?