Javascript MapBox map.setView(locale.getLatLng()不工作

Javascript MapBox map.setView(locale.getLatLng()不工作,javascript,ruby-on-rails,mapbox,Javascript,Ruby On Rails,Mapbox,我正在我的站点中实现MapBox。我根据以下内容进行建模: https://www.mapbox.com/guides/building-a-store-locator/ 我已将所有内容设置为当前拉入我在位置/新表单中输入的位置。然后我会在地图旁边显示位置列表,但当我单击位置名称时,地图不会移动到该位置。只有弹出框会显示标记(正确) 现在,当我一直放大到地图的边缘时,我终于看到标记被放置在地图的最底部边缘,而不是任何纬度/经度上 因此,我已经能够确定这并没有从我输入的任何位置的数据库中提取la

我正在我的站点中实现MapBox。我根据以下内容进行建模:

https://www.mapbox.com/guides/building-a-store-locator/
我已将所有内容设置为当前拉入我在位置/新表单中输入的位置。然后我会在地图旁边显示位置列表,但当我单击位置名称时,地图不会移动到该位置。只有弹出框会显示标记(正确)

现在,当我一直放大到地图的边缘时,我终于看到标记被放置在地图的最底部边缘,而不是任何纬度/经度上

因此,我已经能够确定这并没有从我输入的任何位置的数据库中提取lat/long,但我看不出需要在哪里修复它。有人能帮忙吗

LOCATION.RB:

def to_geo_json_feature
{
    "type": "Feature",
    "geometry": 
    {
        "type": "Point",
        "coordinates": [
            latitude,
            longitude
        ]
    },
    "properties": 
    {
        "name": name,
        "address": address1 + ', ' + address2,
        "city": city,
        "country": "United States",
        "zip": zip,
        "state": state
    }
}
end
LOCATIONS.HTML.RB

<script>
L.mapbox.accessToken = '<my access token is here>';
    var geojson = [  
    {
        "type": "FeatureCollection",
        "features": <%= raw Location.all.map(&:to_geo_json_feature).to_json %>
    }];

var map = L.mapbox.map('map', '<my mapbox map id is here>')
.setView([38.909671288923, -77.034084142948], 12);

var listings = document.getElementById('listings');
var locations = L.mapbox.featureLayer().addTo(map);

locations.setGeoJSON(geojson);

function setActive(el) 
{
    var siblings = listings.getElementsByTagName('div');

    for (var i = 0; i < siblings.length; i++) 
    {
        siblings[i].className = siblings[i].className
        .replace(/active/, '').replace(/\s\s*$/, '');
    }

    el.className += ' active';
}

locations.eachLayer(function(locale) 
{
    // Shorten locale.feature.properties to just `prop` so we're not
    // writing this long form over and over again.
    var prop = locale.feature.properties;

    // Each marker on the map.
    var popup = '<h3>' + prop.name + '</h3><div>' + prop.address + '<br>' + prop.city + ', ' + prop.state + ' ' + prop.zip;

    link.onclick = function() 
    {
        setActive(listing);

        // When a menu item is clicked, animate the map to center
        // its associated locale and open its popup.
        map.setView(locale.getLatLng(), 16);
        locale.openPopup();
        return false;
    };

    // Marker interaction
    locale.on('click', function() 
    {
        // 1. center the map on the selected marker.
        map.panTo(locale.getLatLng());

        // 2. Set active the markers associated listing.
        setActive(listing);
    });

    popup += '</div>';
    locale.bindPopup(popup);
});
</script>

L.mapbox.accessToken='';
var geojson=[
{
“类型”:“FeatureCollection”,
“特点”:
}];
var map=L.mapbox.map('map','')
.setView([38.909671288923,-77.034084142948],12);
var listings=document.getElementById('listings');
var locations=L.mapbox.featureLayer().addTo(映射);
setGeoJSON(geojson);
功能设置激活(el)
{
var sides=listings.getElementsByTagName('div');
对于(变量i=0;i<1.length;i++)
{
兄弟姐妹[i].className=兄弟姐妹[i].className
.replace(/active/,“”)。replace(/\s\s*$/,“”);
}
el.className+=‘活动’;
}
locations.eachLayer(函数(区域设置)
{
//将locale.feature.properties缩短为'prop',这样我们就不会
//一遍又一遍地写这个长表格。
var prop=locale.feature.properties;
//地图上的每个标记。
var popup=''+prop.name+'+prop.address+'
'+prop.city+','+prop.state+'+prop.zip; link.onclick=函数() { setActive(上市); //单击菜单项时,将贴图设置为中心动画 //并打开其弹出窗口。 map.setView(locale.getLatLng(),16); locale.openPopup(); 返回false; }; //标记相互作用 locale.on('click',function()) { //1.将地图居中放置在所选标记上。 map.panTo(locale.getLatLng()); //2.设置与列表关联的活动标记。 setActive(上市); }); 弹出+=''; locale.bindpoppup(弹出窗口); });