我试图绘制美国地质勘探局的地震数据,并得到一个非常奇怪的问题。我的查询将获得所有的结果并绘制第一个结果,而其余的结果则追加在地图的顶部。

function getEarthquakes(){
jQuery.ajax({
type: "GET",
dataType: "json",
url: "data/earthquakes-today.json",
error: function (err) { console.log(err)},
success: function (results, status, xhr) {
jQuery(results.features).each(function(index, i) {
L.marker([i.geometry.coordinates[0], i.geometry.coordinates[1]]).bindPopup(i.geometry.coordinates[0]+", "+i.geometry.coordinates[1]).addTo(map);
});
}
})
}知道是什么导致的吗?没有控制台日志错误,当我console.log得到的结果:

发布于 2018-07-08 03:24:32
正如在Plotting geojson points in html中解释的那样,您只需以错误的顺序使用坐标。
考虑到您显示的数据,您似乎在results中收到了一个GeoJSON功能数组。在这种情况下,您可以直接将其输入到L.geoJSON工厂,该工厂将在内部为您逆转坐标顺序:
L.geoJSON(results).addTo(map)否则,确保你自己倒过来:
// [latitude , longitude]
L.marker(([i.geometry.coordinates[1], i.geometry.coordinates[0]])https://stackoverflow.com/questions/51228512
复制相似问题