Javascript 如何将google maps api 3热图与naturalearthdata一起使用
我有来自自然地球的数据,用于国家坐标。这些是数组中的数组中的数组 我的数据(一个国家的示例) 源链接: 示例热图示例中的getPoints函数如下所示Javascript 如何将google maps api 3热图与naturalearthdata一起使用,javascript,google-maps,google-maps-api-3,heatmap,Javascript,Google Maps,Google Maps Api 3,Heatmap,我有来自自然地球的数据,用于国家坐标。这些是数组中的数组中的数组 我的数据(一个国家的示例) 源链接: 示例热图示例中的getPoints函数如下所示 function getPoints() { return [ new google.maps.LatLng(37.782551, -122.445368), new google.maps.LatLng(37.782745, -122.444586), new google.maps.LatLng(3
function getPoints() {
return [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586),
new google.maps.LatLng(37.782842, -122.443688),
...
...
]
}
那么现在如何将这些数据映射到getPoints函数,以便方便地提供lat-long呢?我不知道如何输入这些数据在热图对象基本上 您可以使用此函数(或类似函数)生成坐标对的一维数组
function recursiveArrayPass(source) {
if (typeof source != 'object')
return []
if (typeof source[0] == 'number') {
return [source]
}
var result = []
for (var i = 0; i < source.length; i++)
result = result.concat(recursiveArrayPass(source[i]))
return result
}
函数递归ArrayPass(源代码){
如果(源的类型!=“对象”)
返回[]
如果(源的类型[0]=='number'){
返回[来源]
}
var结果=[]
对于(变量i=0;i
然后在生成的数组上使用类似的内容
function getPoints(coords_array) {
var result = []
for (var i = 0; i < coords_array.length; i++)
result.push(new google.maps.LatLng(coords_array[i][0], coords_array[i][1]));
return result
}
函数获取点(坐标数组){
var结果=[]
对于(var i=0;i
Diana一秒钟前我发布了一条最新消息。我不确定这些是不是很长。我试着手动添加其中的一些,但是这些不是纬度和经度的点的热图不会显示出来。如果它们是地理坐标,则需要知道投影的位置并进行转换。使用自然地球数据比我已经在正确的投影中要容易得多。当我尝试手动添加这些数据时,我也有同样的想法。我找到了Naturaleth的geojson。谢谢
function recursiveArrayPass(source) {
if (typeof source != 'object')
return []
if (typeof source[0] == 'number') {
return [source]
}
var result = []
for (var i = 0; i < source.length; i++)
result = result.concat(recursiveArrayPass(source[i]))
return result
}
function getPoints(coords_array) {
var result = []
for (var i = 0; i < coords_array.length; i++)
result.push(new google.maps.LatLng(coords_array[i][0], coords_array[i][1]));
return result
}