2013-10-18 113 views
1

我非常難以接受我編寫的一些JavaScript/jQuery代碼,這些代碼在Webkit瀏覽器(Chrome和Safari)中完美工作,但在Firefox或IE中根本無法工作,我希望有人能指出我的錯誤?jQuery在Chrome和Safari中工作,但不是Firefox或IE?

我正在做的是用jQuery拉動GeoRSS feed,然後使用Leaflet在地圖上繪製位置點。不知何故,當使用Firefox或IE時,點不會被繪製出來? 這裏的網頁有問題:http://bit.ly/19N0I75

而這裏的代碼:

var map = L.mapbox.map('map', 'primitive.geography-class').setView([42, 22], 4); 

var wordpressIcon = L.icon({ 
iconUrl: 'http://www.shifting-sands.com/wp-content/themes/shiftingsands/images/icons/wordpress.png', 

iconSize:  [18, 18], // size of the icon 
shadowSize: [0, 0], // size of the shadow 
iconAnchor: [9, 9], // point of the icon which will correspond to marker's location 
shadowAnchor: [0, 0], // the same for the shadow 
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor 
}); 

jQuery(document).ready(function($){ 
$.get("http://shifting-sands.com/feed/", function (data) { 
var $xml = $(data); 
var $i = 0; 
$xml.find("item").each(function() { 
    var $this = $(this), 
     item = { 
      title: $this.find("title").text(), 
      linkurl: $this.find("link").text(), 
      description: $this.find("description").text(), 
      pubDate: $this.find("pubDate").text(), 
      latitude: $this.find("lat").text(), 
      longitude: $this.find("long").text() 
     } 

       lat = item.latitude; 
       long = item.longitude; 
       title = item.title; 
       clickurl = item.linkurl; 

       //Get the url for the image. 
       var htmlString = '<h4><a href="' + clickurl + '" target="_blank">' + title + '</a></h4>';      
       var contentString = '<div id="content">' + htmlString + '</div>'; 

       //Create a new marker position using the Leaflet API. 
       var rssmarker = L.marker([lat, long], {icon: wordpressIcon}).addTo(map); 

       //Create a new info window using the Google Maps API 

       rssmarker.bindPopup(contentString, {closeButton: true}); 


    $i++; 
}); 
}); 
}); 

謝謝!

+0

Works on firefox 24 - mac –

+0

「LatLng對象無效」? – adeneo

+0

「mapbox.js中的」錯誤:無效的LatLng對象:(,)「。作爲一個猜測,我會說在對象文字中的最後一個屬性之後有一個尾隨逗號。 –

回答

0

由於緯度值是名稱空間(地理位置:緯度),因此您的find()中沒有任何值。因此,錯誤(,),兩個空值,用逗號分隔。您必須將您的查詢更改爲:

latitude: $this.find("geo\\:lat").text() 

雙反斜槓轉義冒號。

+0

感謝您的幫助。然而令人困惑的是,這在Chrome,Safari和Opera中都有所打破。 下面是您的更改地圖:http://bit.ly/19XLQEL – Tim

+0

解決了它! jQuery中的一個bug意味着它需要爲 'latitude:$ this.find(「geo \\:lat,lat」)。text()' 'longitude:$ this.find(「geo \\:long,長「)。文本()' – Tim

相關問題