MKMapView setRegion to Annotation

时间:2012-12-05 08:53:22

标签: iphone objective-c ios xcode

hy伙计们。如果可能,我需要一些帮助。当我按下地图按钮时,我通过CLLocation属性加载具有经度和纬度的对象。事实上,我不希望地图将区域/中心坐标设置为用户位置,我希望它在加载地图后进入注释区域,所以我这样做:

- (void)loadActiveEstateAnnotation
{
    RE_Annotation *re_annotation = [[RE_Annotation alloc] init];

     if(self.mapView.showsUserLocation == YES)
         NSLog(@"Santa Clause is comming to town");

    re_annotation.longitude = viewingEstate.estateLocation.coordinate.longitude;
    re_annotation.latitude = viewingEstate.estateLocation.coordinate.latitude;
    re_annotation.poiID = [[RE_Shared sharedInstance] selectedEstate];
    re_annotation.title = [NSString stringWithFormat:@"Estate %d",re_annotation.poiID];

    [self.mapView addAnnotation:re_annotation];

    CLLocationCoordinate2D activeAnnotationCoordonate;

    activeAnnotationCoordonate.longitude = re_annotation.longitude;
    activeAnnotationCoordonate.latitude = re_annotation.latitude;

    MKCoordinateSpan activeEstateSpan;

    activeEstateSpan.longitudeDelta = 0.05;
    activeEstateSpan.latitudeDelta = 0.05;


    MKCoordinateRegion activeEstateRegion;

    activeEstateRegion.center = activeAnnotationCoordonate;
    activeEstateRegion.span = activeEstateSpan;

    NSLog(@"----These are the coordinates%f,%f", activeAnnotationCoordonate.longitude, activeAnnotationCoordonate.latitude);   // coordinates are good and valid ive checked them

    [self.mapView setRegion:activeEstateRegion];
    [self.mapView regionThatFits:activeEstateRegion];
    [re_annotation autorelease];

}

所以底线mapview outlet aint设置区域甚至很难坐标很好。然而,它接受我给它的不同跨度,但它仍然始终锁定在用户区域;问题是......为什么?

1 个答案:

答案 0 :(得分:1)

它的发生是因为您的CLLocationManager类每次都使用MKMapView更新位置,所以此处您更新的当前位置设置为MapView的区域

要停止此操作,只需调用此方法..

[yourLocationManager stopUpdatingLocation];
在<{1}}方法中

开始。