1.方法
export function getPointCenter(lonArr, latArr) {
let maxLon = Math.max.apply(Math, lonArr);
let minLon = Math.min.apply(Math, lonArr);
let maxLat = Math.max.apply(Math, latArr);
let minLat = Math.min.apply(Math, latArr);
let lonCenter = ((maxLon - minLon) / 2) + minLon;
let latCenter = ((maxLat - minLat) / 2) + minLat;
return {
lonCenter,
latCenter
};
}
2.使用 传入经纬度数组
const lonArr = []
conts latArr = []
let lonCenter = getPointCenter(lonArr, latArr).lonCenter
let latCenter = getPointCenter(lonArr, latArr).latCenter