views:

358

answers:

2

I managed to load the map cross-browser but when it comes to populating it with markers, it doesn't work in IE7 (markers are not displayed). Everything's fine in Firefox.

The locations are stored in XML which is then parsed by javascript and markers are added.

XML structure:

<?xml version='1.0' standalone='yes'?>    
<stores>
  <store>
    <lat>47.00565</lat> <!-- Note: fake values here -->
    <lng>26.25879</lng>
  </store>
</stores>

jQuery code:

var loadMarkers = function(xml){
  var $allstores = $(xml).find("store");
  for($i=0; $i<$allstores.length; $i++){
    var $store = $allstores.eq($i);
    var marker= new GMarker(new GLatLng($store.find("lat").text(),$store.find("lng").text()));
    MaCarte.addOverlay(marker);
  }
}

It may be useful to know that there are 300+ stores in the XML file.

Did you ever have such a problem?

UPDATE:

The problem seems to be on the XML parsing. Indeed if I alert the number of stores returned like this:

alert($allmagasins.length);

I get "0" on IE and "252" on Firefox. Is jQuery not correctly parsing XML in IE?

A: 

Pasted the wrong link in my comment. http://gmaps-utility-library-dev.googlecode.com/svn/trunk/markermanager/

Here's an example (untested)

var markerManager = new MarkerManager(map)
markerManager.addMarker(marker)
markerManager.refresh();

..fredrik

fredrik
It doesn't seem to be the issue. See my updated question.
Guillaume Flandre
+2  A: 

OK, I found the solution.

When dealing with IE and XML parsing with jQuery, some stuff has to be done in order to make it work.

Here's my updated working jQuery code:

var loadMarkers = function(xml){

  if($.browser.msie){
    var data = xml;
    xml = new ActiveXObject( 'Microsoft.XMLDOM');
    xml.async = false;
    xml.loadXML(data);
  }

  var $allstores = $(xml).find("store");
  for($i=0; $i<$allstores.length; $i++){
    var $store = $allstores.eq($i);
    var marker= new GMarker(new GLatLng($store.find("lat").text(),$store.find("lng").text()));
    MaCarte.addOverlay(marker);
  }
}
Guillaume Flandre