合作联系微信: w6668263      合作联系电话:177-9238-7426     

利用正则快速把经纬度字符串分割成数组。

数据源

var p1 = '114.339292, 22.623357, 114.339406, 22.623397, 114.339546, 22.623634, 114.339632, 22.623882, 114.339685, 22.624288, 114.339803, 22.624476, 114.339793, 22.624981, 114.3399, 22.625447, 114.3402, 22.625833, 114.340436, 22.625882, 114.340715, 22.625793, 114.340994, 22.625872, 114.341359, 22.626051, 114.341938, 22.626348, 114.342411, 22.626605, 114.343183, 22.626595, 114.343312, 22.626595, 114.34343, 22.626684, 114.34343, 22.626813, 114.343612, 22.627417, 114.343494, 22.628091, 114.343644, 22.628308, 114.343762, 22.628388, 114.344406, 22.628417, 114.344749, 22.628586, 114.344867, 22.628725, 114.344943, 22.628903, 114.344964, 22.629151, 114.344824, 22.629369, 114.344706, 22.630299, 114.344331, 22.630894, 114.344331, 22.63128, 114.344406, 22.631329, 114.344556, 22.63128, 114.345436, 22.63128, 114.345683, 22.631339, 114.346101, 22.631696, 114.347657, 22.630795, 114.349256, 22.63121, 114.350854, 22.631448, 114.350961, 22.631408, 114.351144, 22.630963, 114.351401, 22.629755, 114.351712, 22.629269, 114.351809, 22.629022, 114.351798, 22.628507, 114.352066, 22.626962, 114.352765, 22.626574, 114.35417, 22.626257, 114.354385, 22.627238, 114.35461, 22.627337, 114.354728, 22.627257, 114.355082, 22.626713, 114.355029, 22.626366, 114.356101, 22.625465, 114.356134, 22.625366, 114.356134, 22.624623, 114.356198, 22.624574, 114.356316, 22.624584, 114.356917, 22.625227, 114.357528, 22.62495, 114.357625, 22.624654, 114.357582, 22.624218, 114.358387, 22.623911, 114.359213, 22.623941, 114.359556, 22.623862, 114.359771, 22.623733, 114.36005, 22.623396'

分割操作

var arr = p1.replace(/\s+/g, "").split(',')
console.log(JSON.stringify(arr.map((item, n) => {
    return n % 2 == 0 ? [arr[n], arr[n + 1]] : false
}).filter(Boolean).map(item => item.map(Number))))

 

posted on 2022-02-21 10:26  龙行龘龘9527  阅读(161)  评论(0编辑  收藏  举报

导航