Question

I'm a novice coder designing www.localenvironmentsurvey.com. The map on the homepage displays the location of everyone who has filled out the survey, and the map works in Chrome. However none of the markers show up in Firefox or IE.

First, the relevant code from my index.html file:

        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

function load() {
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(44.9672, -103.7716),
    zoom: 3,
  });
  var infoWindow = new google.maps.InfoWindow;

  downloadUrl("phpsqlajax_genxml2.php", function(data) {
    var xml = data.responseXML;
    var survey = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < survey.length; i++) {
      var govname = survey[i].getAttribute("govname");
      var state = survey[i].getAttribute("state");
      var govtype = survey[i].getAttribute("govtype");
      var point = new google.maps.LatLng(
          parseFloat(survey[i].getAttribute("lat")),
          parseFloat(survey[i].getAttribute("lng")));
      var html = "<b>" + govname + "</b> <br/>" + state;
      var marker = new google.maps.Marker({
        map: map,
        position: point,
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });
}


function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function doNothing() {}

Next, this is the code from the phpsqlajax_genxml2.php file:

<?php
require("les.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

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

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

// Select all the rows in the survey table
$query = "SELECT * FROM survey WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

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

// Start XML file, echo parent node
echo '<survey>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
echo '<marker ';
echo 'govname="' . parseToXML($row['govname']) . '" ';
echo 'state="' . parseToXML($row['state']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'govtype="' . $row['govtype'] . '" ';
echo '/>';
}

// End XML file
echo '</survey>';

?>

Any suggestions for how I can get this map working in Firefox and IE would be deeply, deeply appreciated!

Was it helpful?

Solution 2

Thanks, both of you, for your help and feedback. As it happens, the problem was something else entirely: I needed to add this code to my "phpsqlajax_genxml2.php" file:

$xmlStr = str_replace( 'À', '&#192;', $xmlStr ); 
$xmlStr = str_replace( 'Á', '&#193;', $xmlStr ); 
$xmlStr = str_replace( 'Â', '&#194;', $xmlStr ); 
$xmlStr = str_replace( 'Ã', '&#195;', $xmlStr ); 
$xmlStr = str_replace( 'Ä', '&#196;', $xmlStr ); 
$xmlStr = str_replace( 'Å', '&#197;', $xmlStr ); 
$xmlStr = str_replace( 'Æ', '&#198;', $xmlStr ); 
$xmlStr = str_replace( 'Ç', '&#199;', $xmlStr ); 
$xmlStr = str_replace( 'È', '&#200;', $xmlStr ); 
$xmlStr = str_replace( 'É', '&#201;', $xmlStr ); 
$xmlStr = str_replace( 'Ê', '&#202;', $xmlStr ); 
$xmlStr = str_replace( 'Ë', '&#203;', $xmlStr ); 
$xmlStr = str_replace( 'Ì', '&#204;', $xmlStr ); 
$xmlStr = str_replace( 'Í', '&#205;', $xmlStr ); 
$xmlStr = str_replace( 'Î', '&#206;', $xmlStr ); 
$xmlStr = str_replace( 'Ï', '&#207;', $xmlStr ); 
$xmlStr = str_replace( 'Ð', '&#208;', $xmlStr ); 
$xmlStr = str_replace( 'Ñ', '&#209;', $xmlStr ); 
$xmlStr = str_replace( 'Ò', '&#210;', $xmlStr ); 
$xmlStr = str_replace( 'Ó', '&#211;', $xmlStr ); 
$xmlStr = str_replace( 'Ô', '&#212;', $xmlStr ); 
$xmlStr = str_replace( 'Õ', '&#213;', $xmlStr ); 
$xmlStr = str_replace( 'Ö', '&#214;', $xmlStr ); 
$xmlStr = str_replace( '×', '&#215;', $xmlStr );  
$xmlStr = str_replace( 'Ø', '&#216;', $xmlStr ); 
$xmlStr = str_replace( 'Ù', '&#217;', $xmlStr ); 
$xmlStr = str_replace( 'Ú', '&#218;', $xmlStr ); 
$xmlStr = str_replace( 'Û', '&#219;', $xmlStr ); 
$xmlStr = str_replace( 'Ü', '&#220;', $xmlStr ); 
$xmlStr = str_replace( 'Ý', '&#221;', $xmlStr ); 
$xmlStr = str_replace( 'Þ', '&#222;', $xmlStr ); 
$xmlStr = str_replace( 'ß', '&#223;', $xmlStr ); 
$xmlStr = str_replace( 'à', '&#224;', $xmlStr ); 
$xmlStr = str_replace( 'á', '&#225;', $xmlStr ); 
$xmlStr = str_replace( 'â', '&#226;', $xmlStr ); 
$xmlStr = str_replace( 'ã', '&#227;', $xmlStr ); 
$xmlStr = str_replace( 'ä', '&#228;', $xmlStr ); 
$xmlStr = str_replace( 'å', '&#229;', $xmlStr ); 
$xmlStr = str_replace( 'æ', '&#230;', $xmlStr ); 
$xmlStr = str_replace( 'ç', '&#231;', $xmlStr ); 
$xmlStr = str_replace( 'è', '&#232;', $xmlStr ); 
$xmlStr = str_replace( 'é', '&#233;', $xmlStr ); 
$xmlStr = str_replace( 'ê', '&#234;', $xmlStr ); 
$xmlStr = str_replace( 'ë', '&#235;', $xmlStr ); 
$xmlStr = str_replace( 'ì', '&#236;', $xmlStr ); 
$xmlStr = str_replace( 'í', '&#237;', $xmlStr ); 
$xmlStr = str_replace( 'î', '&#238;', $xmlStr ); 
$xmlStr = str_replace( 'ï', '&#239;', $xmlStr ); 
$xmlStr = str_replace( 'ð', '&#240;', $xmlStr ); 
$xmlStr = str_replace( 'ñ', '&#241;', $xmlStr ); 
$xmlStr = str_replace( 'ò', '&#242;', $xmlStr ); 
$xmlStr = str_replace( 'ó', '&#243;', $xmlStr ); 
$xmlStr = str_replace( 'ô', '&#244;', $xmlStr ); 
$xmlStr = str_replace( 'õ', '&#245;', $xmlStr ); 
$xmlStr = str_replace( 'ö', '&#246;', $xmlStr ); 
$xmlStr = str_replace( '÷', '&#247;', $xmlStr );
$xmlStr = str_replace( 'ø', '&#248;', $xmlStr ); 
$xmlStr = str_replace( 'ù', '&#249;', $xmlStr ); 
$xmlStr = str_replace( 'ú', '&#250;', $xmlStr ); 
$xmlStr = str_replace( 'û', '&#251;', $xmlStr ); 
$xmlStr = str_replace( 'ü', '&#252;', $xmlStr ); 
$xmlStr = str_replace( 'ý', '&#253;', $xmlStr ); 
$xmlStr = str_replace( 'þ', '&#254;', $xmlStr ); 
$xmlStr = str_replace( 'ÿ', '&#255;', $xmlStr ); 

This is because the city and county names people were submitting included unusual characters beyond the usual apostrophes and amperstands, and I needed to parse all of these to xml, otherwise the markers wouldn't load in Firefox and IE.

OTHER TIPS

Actually its known bug to loading marker icon(image) .Check mozilla support page.This issue has been fixed in Firefox version 13 , i would suggest switch to latest version of Firefox and check.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top