Mapbox:当我尝试更改geojson对象的纬度/经度时,列表不起作用

时间:2014-11-19 19:30:52

标签: javascript mapbox geojson

我尝试了这段代码并且完美无缺,直到我尝试更改标记的位置。例如,在geojson数组中,我更改了第一个变量的属性,当我在列表中单击它时,它只显示标记(没有地图)。任何人都可以看到问题可能是什么?

以下是代码:http://plnkr.co/edit/ohumVwCE0CqcZOIkzPTa?p=preview

var geojson = [{
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [
        34.022591187904126, -118.28702688217165
      ]
    },
    "properties": {
      "phoneFormatted": "(213) 748-5116",
      "phone": "2022347336",
      "address": "1665 W Jefferson Blvd",
      "city": "Los Angeles",
      "country": "United States",
      "crossStreet": "at Jefferson",
      "postalCode": "90007",
      "state": "CA"
    }
  }, {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [-77.049766,
        38.900772
      ]
    },
    "properties": {
      "phoneFormatted": "(202) 507-8357",
      "phone": "2025078357",
      "address": "2221 I St NW",
      "city": "Washington DC",
      "country": "United States",
      "crossStreet": "at 22nd St NW",
      "postalCode": "20037",
      "state": "D.C."
    }

如您所见,列表中的第一项会将您带到一个无法识别的位置。但其他项目工作正常。

1 个答案:

答案 0 :(得分:0)

您似乎已经交换了纬度和经度:

"coordinates": [
    34.022591187904126, -118.28702688217165
]

这是无效的,纬度现在超过-90/90的界限,地图不知道该怎么办。如果你交换它们,它可以很好地工作:

"coordinates": [
    -118.28702688217165, 34.022591187904126
]