Uncaught TypeError: Cannot read property '0' of undefined with MapBox

Uncaught TypeError: Cannot read property '0' of undefined with MapBox

我的函数 showMap 的参数数据似乎不起作用。我有 undefined 对应 data.latlng & data.lbounds。我不知道如何调试这个。我的代码之前运行良好...

感谢您的帮助。

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 工作正常。事实上,这是我的地址不起作用,因为里面有一个逗号。嗯,谢谢。

我找到了。这是一个非常愚蠢的问题。数据工作正常。事实上,这是我的地址不起作用,因为里面有一个逗号。嗯,谢谢。