我一直在努力将我的所有坐标数组推入一个对象,但我似乎无法找到如何使用angular找到并推动坐标数组。
我以为我可以使用angular.forEach来实现这一目标,但我无法让它发挥作用。我试图找到答案和教程,但似乎没有什么能满足我的需要。我可能没有完全理解。
这是我的JSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
22.5792379347961,
32.700558883278
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
22.5794856682809,
34.7005532568414
]
}
}
]
}
这是我最近的尝试:
$scope.coordinates = [];
$scope.features = response.data.features;
angular.forEach($scope.features, function(features){
angular.forEach(features.geometry, function(geometry){
$scope.coordinates.push(geometry.coordinates);
});
});
非常感谢任何有关如何完成此任务的教程参考或示例(甚至更好)!
我正在寻找以下结果:
"coordinates": [
[22.5792379347961, 32.700558883278],
[22.5794856682809, 34.7005532568414]
]
答案 0 :(得分:0)
试试这个:
$scope.coordinates = [];
$scope.features = response.data.features;
angular.forEach($scope.features, function(features){
$scope.coordinates.push(features.geometry.coordinates);
});