【问题标题】:MKMapView setRegion to AnnotationMKMapView setRegion 到 Annotation
【发布时间】:2012-12-05 08:53:22
【问题描述】:

各位。如果你可以的话,我需要一些帮助。当我按下地图按钮时,我通过 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 出口不是设置区域,即使坐标也很好。但是,它确实接受了我给它的不同跨度,但它仍然始终锁定在用户区域;问题是……为什么?

【问题讨论】:

    标签: iphone objective-c ios xcode


    【解决方案1】:

    发生这种情况是因为您的 CLLocationManager 类每次都使用您的 MKMapView 更新位置,所以在这里您更新的当前位置被设置为 MapView 的区域

    要停止这个,只需调用这个方法..

    [yourLocationManager stopUpdatingLocation];
    

    在您的 loadActiveEstateAnnotation 方法中开始。

    【讨论】:

      猜你喜欢
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 2014-05-31
      • 1970-01-01
      相关资源
      最近更新 更多