/**
 * 根据一组点位([纬度,经度])计算出中心点
 * @param pointArray
 * @returns {*[]}
 */
const calculateCenterPoint=(pointArray)=>{
  const sortedLongitudeArray=pointArray.map(item=>item.lng).sort();
  const sortedLatitudeArray=pointArray.map(item=>item.lat).sort();
  const centerLongitude=((sortedLongitudeArray[0]+sortedLongitudeArray[sortedLongitudeArray.length-1])/2).toFixed(4);
  const centerLatitude=((sortedLatitudeArray[0]+sortedLatitudeArray[sortedLatitudeArray.length-1])/2).toFixed(4);
  return [centerLongitude,centerLatitude];
};

export default calculateCenterPoint;

 

相关文章:

  • 2022-12-23
  • 2022-02-06
  • 2021-12-04
  • 2021-08-18
  • 2021-12-04
  • 2021-06-20
猜你喜欢
  • 2021-06-10
  • 2021-11-17
  • 2022-03-03
  • 2022-12-23
  • 2021-12-13
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案