欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过经纬度获取中心点,以及绑定的缩放级别

程序员文章站 2022-03-16 15:15:50
...

//根据经纬度的距离获取地图的缩放级
function getRoom(diff){
var room = new Array(0, 1, 2, 3, 4, 5, 6,7,8, 9, 10, 11, 12, 13, 14);
var diffArr = new Array(360,180,90,45,22,11,5,2.5,1.25,0.6,0.3,0.15,0.07,0.03,0);
for(var i = 0; i < diffArr.length; i ++){
if((diff - diffArr[i]) >= 0){
return room[i];
}
}
return 14;
}


function getCenterPoint(maxJ,minJ,maxW,minW){//通过经纬度获取中心位置和缩放级别
if(maxJ==minJ&&maxW==minW)return [maxJ,maxW,0];
var diff = maxJ - minJ;
if(diff < (maxW - minW))diff = maxW - minW;
diff = parseInt(10000 * diff)/10000;
var centerJ = minJ*1000000+1000000*(maxJ - minJ)/2;
var centerW = minW*1000000+1000000*(maxW - minW)/2;
var zoom = getRoom(diff);
return [centerJ/1000000,centerW/1000000,zoom];
}

相关标签: 360