如何用地圖經緯度計算給出中心位置


/**
 * 根據一組點位([緯度,經度])計算出中心點
 * @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