【问题标题】:Google Map Markers Appear in Chrome but not in Firefox or IE谷歌地图标记出现在 Chrome 中,但不在 Firefox 或 IE 中
【发布时间】:2014-06-29 16:20:12
【问题描述】:

我是设计 www.localenvironmentsurvey.com 的新手编码员。主页上的地图显示了填写调查表的每个人的位置,并且该地图在 Chrome 中运行。但是,Firefox 或 IE 中没有显示任何标记。

首先,我的 index.html 文件中的相关代码:

        <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() {}

接下来,这是 phpsqlajax_genxml2.php 文件中的代码:

<?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>';

?>

任何关于如何让这张地图在 Firefox 和 IE 中工作的建议都将不胜感激!

【问题讨论】:

  • 标记选项中有多余的逗号:position: point,。在 console.log 中报告了一些错误。在 Chrome 和 FF 中也是如此。

标签: javascript mysql google-chrome firefox google-maps-api-3


【解决方案1】:

实际上是加载标记图标(图像)的已知错误。检查mozilla support page。此问题已在 Firefox 版本 13 中修复,我建议切换到最新版本的 Firefox 并检查。

【讨论】:

    【解决方案2】:

    感谢你们两位的帮助和反馈。碰巧,问题完全是另外一回事:我需要将此代码添加到我的“phpsqlajax_genxml2.php”文件中:

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

    这是因为人们提交的城市和县名包含除了通常的撇号和符号之外的不寻常字符,我需要将所有这些解析为 xml,否则标记不会在 Firefox 和 IE 中加载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 2012-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 1970-01-01
      相关资源
      最近更新 更多