Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图标记出现在Chrome中,但不出现在Firefox或IE中_Javascript_Mysql_Google Chrome_Firefox_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图标记出现在Chrome中,但不出现在Firefox或IE中

Javascript 谷歌地图标记出现在Chrome中,但不出现在Firefox或IE中,javascript,mysql,google-chrome,firefox,google-maps-api-3,Javascript,Mysql,Google Chrome,Firefox,Google Maps Api 3,我是设计www.localenvironmentsurvey.com的新手。主页上的地图显示了填写调查的每个人的位置,该地图在Chrome中工作。然而,Firefox或IE中没有出现任何标记 首先,我的index.html文件中的相关代码: <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script

我是设计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() {}

函数加载(){
var map=new google.maps.map(document.getElementById(“map”){
中心:新google.maps.LatLng(44.9672,-103.7716),
缩放:3,
});
var infoWindow=new google.maps.infoWindow;
下载URL(“phpsqlajax_genxml2.php”,函数(数据){
var xml=data.responseXML;
var survey=xml.documentElement.getElementsByTagName(“标记”);
对于(变量i=0;i“+状态;
var marker=new google.maps.marker({
地图:地图,
位置:点,,
});
bindInfoWindow(标记、地图、infoWindow、html);
}
});
}
函数bindInfoWindow(标记、地图、infoWindow、html){
google.maps.event.addListener(标记'click',函数(){
setContent(html);
信息窗口。打开(地图、标记);
});
}
函数下载url(url,回调){
var请求=window.ActiveXObject?
新的ActiveXObject('Microsoft.XMLHTTP'):
新的XMLHttpRequest;
request.onreadystatechange=函数(){
if(request.readyState==4){
request.onreadystatechange=doNothing;
回调(请求、请求、状态);
}
};
打开('GET',url,true);
请求发送(空);
}
函数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>';

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

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

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


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

标记选项中有多余的逗号:
位置:点,
。console.log中报告了一些错误。同样的铬和FF。