如何用地图经纬度计算给出中心位置


/**
 * 根据一组点位([纬度,经度])计算出中心点
 * @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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM