我有一个名为坐标
的数组,它存储多边形的纬度和经度。我想获取存储在该数组中的最大和最小纬度/经度。
我的逻辑是使用array.filter()
方法来过滤值,但我的控制台一直说
coordinate.filter is not a function
// this is to get coordinate(lat and lng) of a map, lats and lng are being stored in array named coordinate
var coordinate = [];
for (var i = 0; i < polygon.getPath().getLength(); i++) {
coordinate += polygon.getPath().getAt(i).toUrlValue(6) + ",";
}
var results =coordinate.filter(function(value) {
return(value< 0);
}
);
alert(coordinate);
})
最佳答案
您需要确保您的坐标是一个数组。查看您的评论,您希望在坐标数组中找到最小值和最大值,可以通过以下方式完成:
if(Array.isArray(coordinate)){
let min = coordinate.reduce((a,b) => Math.min(a,b));
let max = coordinate.reduce((a,b) => Math.max(a,b));
}
关于javascript - 多边形 array.filter() typeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788395/