javascript - How to make an appropriate array for coordinates?
问题描述
I have an array that returns 28 (latitude and longitude). I'll format to send to database, so here my questions:
- As you can see, the latitude and longitude comes always together, how can i separate? 2.the bold lines always return the same coordinate, how can I remove to send the minimal to database?
Code below:
var capturaCoordenada = [];
if (data.waypoints.length === 12) {
for (var i = 0; i < capturaCoordenada.length; i++) {
exibeCoordenada = exibeCoordenada + "\n" + capturaCoordenada[i] + capturaCoordenada[i++]; }
exibeCoordenada = exibeCoordenada + "\n";
window.alert(exibeCoordenada);
OBS: I receive the coordinates like this:
Data:
-49.3766505877158,-20.80796326493855-49.3766505877158,-20.80796326493855 -49.37949730565916,-20.80670816431558-49.37949730565916,-20.80670816431558 -49.38166453054308,-20.805324135912116-49.38166453054308,-20.805324135912116 -49.38413216283695,-20.806146531132384-49.38413216283695,-20.806146531132384 -49.38209368398577,-20.80891456013579-49.38209368398577,-20.80891456013579 -49.37981917074134,-20.81096046195445-49.37981917074134,-20.81096046195445 -49.37743736913569,-20.811140981370414-49.37743736913569,-20.811140981370414
解决方案
在这部分代码中
exibeCoordenada = exibeCoordenada + "\n" + capturaCoordenada[i] + capturaCoordenada[i++];
您要添加两次相同的内容,尝试删除其中一个,如下所示:
exibeCoordenada = exibeCoordenada + "\n" + capturaCoordenada[i];
然后你应该有一个如下所示的结果
-49.3766505877158,-20.80796326493855
-49.37949730565916,-20.80670816431558
-49.38166453054308,-20.805324135912116
您应该能够将字符串转换为列表,如下所示:
exibeCoordenada.split("\n").map(x => x.split(","))
这给了你这个:
[["-49.3766505877158", "-20.80796326493855"], ["-49.37949730565916", "-20.80670816431558"], ["-49.38166453054308", "-20.805324135912116"]]
推荐阅读
- python - 如何使用 numpy 数组保存 python 字典?
- flutter - 未处理的异常:NoSuchMethodError:在 null 上调用了方法“插入”。扑
- amazon-web-services - CloudFront:从负载中识别的服务名称与传输标头中指定的服务名称不一致
- ironpython - 在 spotfire 中以编程方式更改交叉表颜色
- mysql - 警告 | 第3156章 从第 1 行的列 json_search 到 INTEGER 的 CAST 的 JSON 值无效 |
- python - 如何使 QTableWidget 大小随内容缩放(PyQt5)?
- firebase - Firebase 存储 - 将目录下载为“.zip”
- reactjs - 反应原生的标签
- reactjs - 通过 mdbreact 设计组件
- c# - 转换为字节数组,以便我可以使用 ATOB 解码