Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

高德地图的矩形计算

需求:在高德地图上选定一个目标点,将这个点周边5公里内的矩形四个点的坐标找出来


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
/* 
* 根据中心点坐标和距离(米),计算范围
*/
function haversineLnglat(orign, dist){
  let radius = 6378137
  // 求东西两侧的的范围边界。在haversin公式中令φ1 = φ2(维度相同)
  let lat = toRadians(orign[1])
  let dlng = 2 * Math.asin(Math.sin(dist / (2 * radius)) / Math.cos(lat));
  // 弧度转换成角度
  dlng = toDegrees(dlng);
  // 然后求南北两侧的范围边界,在haversin公式中令 Δλ = 0
  let dlat = dist / 6378137;
  // 弧度转换成角度
  dlat = toDegrees(dlat);
  return [orign[0] - dlng, orign[1] - dlat, orign[0] + dlng, orign[1] + dlat]
}
function toRadians(_){
  return _ * Math.PI / 180
}
function toDegrees(_){
  return _ * 180 / Math.PI
}
//haversineLnglat([117, 34], 5000) //[116.94582179841282, 33.955084235794025, 117.05417820158718, 34.044915764205975]
//haversineLnglat([117, 34], 6000) //[116.93498615776213, 33.94610108295283, 117.06501384223787, 34.05389891704717]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...