我是编程新手,我正在尝试在传单地图中显示许可证信息。许可证数据来自 Socrata 的视图。我按照http://fire.seattle.io/代码弄清楚如何做到这一点并设法自己重新创建地图,但是当我尝试使用所需的视图时,我不断收到错误“未捕获的错误:无效的 LatLng 对象:(空,空)”。
视图有几条没有坐标信息的记录;我想过滤视图,所以我只能收到有效的记录,但到目前为止我还没有弄清楚。在 API 端点中使用 where 子句(使用带有资源的 url)我可以进行过滤,但我得到一个未定义的警告和指向我的 jquery 的错误“Uncaught TypeError: Cannot read property 'length' of undefined”。
我正在关注的应用程序中的代码使用另一个 url 来访问数据(使用带有 api/views 的 url),但我无法进行任何过滤或选择(继续获取具有空坐标的记录)。
如何消除那些具有空值的记录,以便我可以在传单地图中显示数据?任何帮助表示赞赏...
代码是...
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Just a test</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.6/mapbox.js'></script>
<script src='http://fire.seattle.io/js/leaflet/leaflet.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.6/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
$.getJSON('https://data.pr.gov/api/views/93ae-6ffm/rows.json?jsonp=?&max_rows=2', function(results) {
console.log(results.data);
var map = L.map('map').setView([18.25,-66.45], 9);
// add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.each(results.data, function(index, value) {
L.marker([value[28], value[29]]).addTo(map)
.bindPopup('<h6>' + value[6] + '</h6>' + value[7] + '<br>');
});
});
</script>
</body>
</html>
谢谢