在 JavaScript 中将字符串坐标列表转换为经纬度坐标的两个浮点数列表?
假设以下为我们的坐标 −
var listOfStrings = ["10.45322,-6.8766363", "78.93664664,-9.74646646", "7888.7664664,-10.64664632"];
要将上述坐标转换为经纬度的两个浮点数列表,请使用 split() based on comma(,) along with map()。
示例
var listOfStrings = ["10.45322,-6.8766363", "78.93664664,-9.74646646", "7888.7664664,-10.64664632"];
var latitude = [];
var longitude = [];
listOfStrings.forEach(obj => obj.split(',')
.map(Number)
.forEach((value, index) => [latitude, longitude][index].push(value))
);
console.log("All positive value is latitude=")
console.log(latitude);
console.log("All negative value is longitude=")
console.log(longitude);要运行上述程序,你需要使用以下命令 −
node fileName.js.
此处,我的文件名是 demo180.js。
输出
这将产生以下输出 −
PS C:\Users\Amit\javascript-code> node demo180.js All positive value is latitude= [ 10.45322, 78.93664664, 7888.7664664 ] All negative value is longitude= [ -6.8766363, -9.74646646, -10.64664632 ]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP