第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

定位MKMapView以一次顯示多個注釋

定位MKMapView以一次顯示多個注釋

iOS
慕虎7371278 2020-02-03 15:16:46
我有幾個要添加到我的MKMapView的注釋(它可以是0-n個項目,其中n通常約為5)。我可以很好地添加注釋,但是我想立即調整地圖的大小以適合屏幕上的所有注釋,而且我不確定該怎么做。我一直在看,-regionThatFits:但是我不確定該怎么做。我將發(fā)布一些代碼以顯示到目前為止的內容。我認為這應該是一項通常很簡單的任務,但到目前為止,我對MapKit感到有些不知所措。- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{location = newLocation.coordinate;//One location is obtained.. just zoom to that locationMKCoordinateRegion region;region.center = location;//Set Zoom level using SpanMKCoordinateSpan span;span.latitudeDelta = 0.015;span.longitudeDelta = 0.015;region.span = span;// Set the region here... but I want this to be a dynamic size// Obviously this should be set after I've added my annotations[mapView setRegion:region animated:YES];// Test data, using these as annotations for nowNSArray *arr = [NSArray arrayWithObjects:@"one", @"two", @"three", @"four", nil];float ex = 0.01;for (NSString *s in arr) {    JBAnnotation *placemark = [[JBAnnotation alloc] initWithLat:(location.latitude + ex) lon:location.longitude];    [mapView addAnnotation:placemark];    ex = ex + 0.005;}    // What do I do here?    [mapView setRegion:[mapView regionThatFits:region] animated:YES];}請注意,這一切都是在我收到位置更新信息時發(fā)生的...我不知道這是否合適。如果沒有,哪里會有更好的地方?-viewDidLoad?提前致謝。
查看完整描述

4 回答

?
縹緲止盈

TA貢獻2041條經驗 獲得超4個贊

從iOS7開始,您可以使用showAnnotations:animated:


[mapView showAnnotations:annotations animated:YES];


查看完整回答
反對 回復 2020-02-03
?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

為什么這么復雜?


MKCoordinateRegion coordinateRegionForCoordinates(CLLocationCoordinate2D *coords, NSUInteger coordCount) {

    MKMapRect r = MKMapRectNull;

    for (NSUInteger i=0; i < coordCount; ++i) {

        MKMapPoint p = MKMapPointForCoordinate(coords[i]);

        r = MKMapRectUnion(r, MKMapRectMake(p.x, p.y, 0, 0));

    }

    return MKCoordinateRegionForMapRect(r);

}


查看完整回答
反對 回復 2020-02-03
  • 4 回答
  • 0 關注
  • 893 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號