gpt4 book ai didi

javascript - 如何使用 JavaScript 将 GeoJSON 保存到文件中

转载 作者:行者123 更新时间:2023-12-03 05:41:30 25 4
gpt4 key购买 nike

我想知道我是否有一个 GeoJSON 对象,例如

var geoJSONLoc= {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"timeReported": "2013-01-22 08:42:26+01"
},
"geometry": {
"type": "Point",
"coordinates": [
7.582512743,
51.933292258,
1
]
}
},
{
"type": "Feature",
"properties": {
"timeReported": "2013-01-22 10:00:26+01"
},
"geometry": {
"type": "Point",
"coordinates": [
7.602516645,
51.94962073,
1
]
}
}]}

如何将其保存到 .json 文件中以供将来使用?

我正在尝试使用

  localStorage.setItem('geoJSONLoc.json', geoJSONLoc); 

但这似乎不是正确的答案。

最佳答案

我在 NodeJS 中做了一些工作,所以这可能有点离谱。但是你不能使用 fs 模块吗?

类似的东西

var fs = require('fs')
fs.writeFile('geoJSONLoc.json', geoJSONLoc, function(err){
if(err){
console.log(err);
}
});

关于javascript - 如何使用 JavaScript 将 GeoJSON 保存到文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40514743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com