2015-07-20 168 views
0

我的函數showMap的參數數據似乎不起作用。我有undefineddata.latlng & data.lbounds。我不知道如何調試。我的代碼以前工作得很好...Uncaught TypeError:無法通過MapBox讀取未定義的屬性'0'

感謝您的幫助。

window.setTimeout(initMap, 100); 

function initMap() { 
    //this should check if your leaflet is available or wait if not. 
    if(typeof L === "undefined"){ 
     window.setTimeout(initMap, 100); 
     return; 
    } 

    L.mapbox.accessToken = 'myAccessToken'; 
    $('.map').each(function() { 
     var map = L.mapbox.map($(this).attr('id'), 'mapbox.streets', {zoomControl:false}).setView([48.855, 2.4], 8); 

     var geocoder = L.mapbox.geocoder('mapbox.places'); 
     var adress = document.getElementById($(this).attr('id')); 

     geocoder.query(adress.getAttribute("data-adress-map"), showMap); 

     function showMap(err, data) { 
      // The geocoder can return an area, like a city, or a 
      // point, like an address. Here we handle both cases, 
      // by fitting the map bounds to an area or zooming to a point. 
      if (data.lbounds) { 
       map.fitBounds(data.lbounds); 
      } 
      else if (data.latlng) { 
       map.setView([data.latlng[0], data.latlng[1]], 13); 
      } 

      var marker = L.marker([data.latlng[0], data.latlng[1]]).addTo(map); 

      marker.bindPopup(adress.getAttribute("data-title-map") +"<br>"+ adress.getAttribute("data-adress-map")); 

      new L.Control.Zoom({ position: 'bottomright' }).addTo(map); 
     } 

    }); 

} 

編輯:

我發現。這是一個非常愚蠢的問題。 data工作正常。事實上,這是我的地址不起作用的原因內部的逗號。非常感謝。

+0

數據包含什麼? – depperm

+0

如果您找到答案,請關閉此問題。 – tmcw

回答

0

我找到了。這是一個非常愚蠢的問題。數據正常工作。事實上,這是我的地址不起作用的原因內部的逗號。非常感謝。

相關問題