关闭

[置顶] iOS 求两经纬度中心点,并返回缩放级别,可以参考

84人阅读 评论(0) 收藏 举报
分类:
+(void)middleCLLocationCoordinate:(CLLocationCoordinate2D)location1 andCllocationCoordinate:(CLLocationCoordinate2D)location2 LOcationCompleteBlock:(MiddleLocationCompleteBlock)CompleteBlock
{
    double  maxJ = location1.latitude>location2.latitude?location1.latitude:location2.latitude;
    double minJ = location1.latitude<location2.latitude?location1.latitude:location2.latitude;
    
    double maxW = location1.longitude>location2.longitude?location1.longitude:location2.longitude;
    double minW = location1.longitude<location2.longitude?location1.longitude:location2.longitude;
    if(maxJ==minJ&&maxW==minW)
    {
        CompleteBlock(maxJ,maxW,17);
    }
    double diff = maxJ - minJ;
    if(diff < (maxW - minW)){
        diff = maxW - minW;
    }
    
    diff = (10000 * diff)/10000;
    double centerJ = minJ*1000000+1000000*(maxJ - minJ)/2.0;
    double centerW = minW*1000000+1000000*(maxW - minW)/2.0;
    int Mapzoom = 0;
    
    NSArray  *diffArr = [NSArray arrayWithObjects:@"360",@"180",@"90",@"45",@"22",@"11",@"5",@"2.5",@"1.25",@"0.6",@"0.3",@"0.15",@"0.07",@"0.03",@"0",nil];
    for(int i = 0; i < diffArr.count; i++){
        
        if((diff - [diffArr[i] doubleValue]) >= 0){
            Mapzoom = i;
            break;
        }else{
            Mapzoom = 17;
        }
    }
    
    if (CompleteBlock) {
        CompleteBlock(centerJ/1000000,centerW/1000000,Mapzoom);
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:367次
    • 积分:35
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档