美文网首页
iOS 百度地图 在可视范围显示所有标注

iOS 百度地图 在可视范围显示所有标注

作者: 花裤衩子 | 来源:发表于2017-08-11 10:13 被阅读0次

    RT :

    
    - (void)mapViewFitAnnotations:(NSArray *)locations
    
    {
    
    if (locations.count < 2) return;
    
    CLLocationCoordinate2D coor = [locations[0] coordinate];
    
    BMKMapPoint pt = BMKMapPointForCoordinate(coor);
    
    CGFloat ltX, ltY, rbX, rbY;
    
    ltX = pt.x, ltY = pt.y;
    
    rbX = pt.x, rbY = pt.y;
    
    for (int i = 1; i < locations.count; i++) {
    
    CLLocationCoordinate2D coor = [locations[i] coordinate];
    
    BMKMapPoint pt = BMKMapPointForCoordinate(coor);
    
    if (pt.x < ltX) ltX = pt.x;
    
    if (pt.x > rbX) rbX = pt.x;
    
    if (pt.y > ltY) ltY = pt.y;
    
    if (pt.y < rbY) rbY = pt.y;
    
    }
    
    BMKMapRect rect;
    
    rect.origin = BMKMapPointMake(ltX , ltY);
    
    rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);
    
    [_mapView setVisibleMapRect:rect];
    
    _mapView.zoomLevel = _mapView.zoomLevel - 0.3;
    
    }
    

    PS :可在改变zoomLevel时加一个是否超出最小范围的判断,转载请注明哦!

    相关文章

      网友评论

          本文标题:iOS 百度地图 在可视范围显示所有标注

          本文链接:https://www.haomeiwen.com/subject/hwllrxtx.html