麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

iOS根據坐標數據點所在的坐標區域來動態顯示到可視范圍

2019-11-14 20:22:51
字體:
來源:轉載
供稿:網友

在地圖上標注很多點之后,地圖的中心點可以設置,但是縮放級別用起來就有點囧了,

所以,就需要根據坐標數據點所在的坐標區域來動態計算,把所有點都剛好顯示到地圖的可視范圍內。

直接上代碼:

 

    //清理坐標數據的視圖和數據    [_bMapView removeAnnotations:_mapAnnotations];    [_mapAnnotations removeAllObjects];    [_carPointArray removeAllObjects];    //聲明解析時對坐標數據的位置區域的篩選,包括經度和緯度的最小值和最大值    CLLocationDegrees minLat;    CLLocationDegrees maxLat;    CLLocationDegrees minLon;    CLLocationDegrees maxLon;    //解析數據    for (int i=0; i<rows.count; i++) {        NSDictionary *row = [rows objectAtIndex:i];        坐標模型類 *item = [[坐標模型類 alloc] initWithJson:row];        if (item.vehicleNo && [item.vehicleNo length]>0) {            標注模型類 *annotation = [[標注模型類 alloc] init];            annotation.coordinate = item.baiduCoordinate;            annotation.item = item;            [_mapAnnotations addObject:annotation];            [_bMapView addAnnotation:annotation];            [annotation release];                        if (i==0) {                //以第一個坐標點做初始值                minLat = item.baiduCoordinate.latitude;                maxLat = item.baiduCoordinate.latitude;                minLon = item.baiduCoordinate.longitude;                maxLon = item.baiduCoordinate.longitude;            }else{                //對比篩選出最小緯度,最大緯度;最小經度,最大經度                minLat = MIN(minLat, item.baiduCoordinate.latitude);                maxLat = MAX(maxLat, item.baiduCoordinate.latitude);                minLon = MIN(minLon, item.baiduCoordinate.longitude);                maxLon = MAX(maxLon, item.baiduCoordinate.longitude);            }                        [_carPointArray addObject:item];        }        [item release];    }    //動態的根據坐標數據的區域,來確定地圖的顯示中心點和縮放級別    if (_carPointArray.count > 0) {        //計算中心點        CLLocationCoordinate2D centCoor;        centCoor.latitude = (CLLocationDegrees)((maxLat+minLat) * 0.5f);        centCoor.longitude = (CLLocationDegrees)((maxLon+minLon) * 0.5f);        BMKCoordinateSpan span;        //計算地理位置的跨度        span.latitudeDelta = maxLat - minLat;        span.longitudeDelta = maxLon - minLon;        //得出數據的坐標區域        BMKCoordinateRegion region = BMKCoordinateRegionMake(centCoor, span);        //百度地圖的坐標范圍轉換成相對視圖的位置        CGRect fitRect = [_bMapView convertRegion:region toRectToView:_bMapView];        //將地圖視圖的位置轉換成地圖的位置        BMKMaPRect fitMapRect = [_bMapView convertRect:fitRect toMapRectFromView:_bMapView];        //設置地圖可視范圍為數據所在的地圖位置        [_bMapView setVisibleMapRect:fitMapRect animated:YES];            }

  

補充:

MKMapRect zoomRect = MKMapRectNull;for (id <MKAnnotation> annotation in mapView.annotations) {    MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);    if (MKMapRectIsNull(zoomRect)) {        zoomRect = pointRect;    } else {        zoomRect = MKMapRectUnion(zoomRect, pointRect);    }}[mapView setVisibleMapRect:zoomRect animated:YES];

  

 

 

最后來張效果圖:

 

 


上一篇:Swift之?和!

下一篇:GCD,60秒獲取驗證碼

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久久久久久国产精品 | 欧美十区| 成人性视频免费网站下载软件 | 日本在线播放一区二区 | 91精品动漫在线观看 | 成人小视频在线播放 | 91久久另类重口变态 | 乱淫67194| 亚洲精品一区二区三区免 | 免费国产网站 | 精品偷拍久久 | 国产免费黄色 | 综合网日日天干夜夜久久 | 2023av在线视频 | 久久久久se| 国产精品久久久久久久久久东京 | 一级视频网站 | 一级毛片大片 | 欧美高清在线精品一区二区不卡 | 中文字幕四区 | 国产亚洲精品精 | 国产一级淫片免费看 | av免费在线播放网址 | h视频在线免费观看 | 欧美一级特级 | 狠狠99 | 久久久一区二区三区四区 | 天天色图片 | 特级毛片全部免费播放器 | 国产1区在线观看 | 女人叉开腿让男人桶 | 国产精品av久久久久久网址 | 国产精品久久久久久影视 | 久久久久久中文字幕 | 亚洲3p激情在线观看 | 91精品免费观看 | 性生活视频软件 | 精品一区在线视频 | 主播粉嫩国产在线精品 | 中文字幕在线成人 | 欧美三级欧美成人高清www |