开发者

Google Map Markers Not Showing in Firefox

I wonder whether someone may be able to help me please.

I'm using the coding below to retrieve google map co-ordinates and add the associated markers on a google map. The coding works perfectly in Internet Explorer, but I have problems when using Firefox. The map is created, but none of the markers have been added.

Could someone perhaps please take a look at this and let me know where I'm going wrong.

Many thanks and regards

Chris

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>All Locations</title>
        <link rel="stylesheet" href="css/alllocationsstyle.css" type="text/css" media="all" />
        <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
        <script type="text/javascript"> 
            var customIcons = {
            0: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            },
            1: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            }
            };

            function load() { 
            var map = new google.maps.Map(document.getElementById("map"), { 
            center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
            zoom:6, 
            mapTypeId: 'roadmap' 
            }); 

            // Change this depending on the name of your PHP file 
            downloadUrl("phpfile.php", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker"); 
            for (var i = 0; i < markers.length; i++) { 
            var locationname = markers[i].getAttribute("locationname"); 
            var address = markers[i].getAttribute("address");
            var finds = markers[i].getAttribute("finds");
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("osgb36lat")), 
            parseFloat(markers[i].getAttribute("osgb36lon")));
            var icon = customIcons[finds] || {};
            var marker = new google.maps.Marker({          
            map: map, 
            position: point,
            title: locationname + ' - ' + address,
            icon: icon.icon,
            shadow: icon.shadow
            }); 
            } 
            }); 
            } 
            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() {} 

            </script> 
            </head> 

            <body onLoad="load()">
                <div id="map"></div>
            </body> 
            </html>

PHP Code

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

// Start XML file, create parent node 

$dom = new DOMDocument("1.0"); 
$node = $dom->createElement("markers"); 
$parnode = $dom->appendChild($node); 

// Opens a connection to a MySQL server 

$connection=mysql_connect ("******", $username, $password); 
if (!$connection) { die('Not connected : ' . mysql_error());} 

// Set the active MySQL database 

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

// Select all the rows in the markers table 

$query = "SELECT * FROM locations WHERE 1"; 
$result = my开发者_C百科sql_query($query); 
if (!$result) { 
die('Invalid query: ' . mysql_error()); 
} 

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

// Iterate through the rows, adding XML nodes for each 

while ($row = @mysql_fetch_assoc($result)){ 
// ADD TO XML DOCUMENT NODE 
$node = $dom->createElement("marker"); 
$newnode = $parnode->appendChild($node); 
$newnode->setAttribute("locationname",$row['locationname']); 
$newnode->setAttribute("address", $row['address']); 
$newnode->setAttribute("osgb36lat", $row['osgb36lat']); 
$newnode->setAttribute("osgb36lon", $row['osgb36lon']); 
$newnode->setAttribute("finds", $row['finds']); 
} 

echo $dom->saveXML(); 

?>


I have the exact same problem and my guess is that you have some apostrophes or other special characters in your query results that are preventing Firefox from loading the XML properly.

EDIT: I actually fixed my problem by using utf8encode() on the columns that were creating the problem. In your case, you could use

$newnode->setAttribute("locationname",utf8encode($row['locationname']));  

in your PHP file, for example.


I have the same problem on my map, the markers are shown after 1 or 2 minutes on Firefox but it work fine on Chrome, problem was an empty shadow url, and I simply solve it by setting a shadow icon for the markers, so on your case re-check your icon.shadow, wish this help you all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜