简体   繁体   English

MKMapView setRegion为注释

[英]MKMapView setRegion to Annotation

hy guys. 大家好 i need some help if u may. 如果可以的话,我需要一些帮助。 when im pressing the map button i load a object wich has longitude and latitude through a CLLocation property. 当我按下地图按钮时,我通过CLLocation属性加载了一个经度和纬度的对象。 thing is, i dont want the map to set the region/center coordinate to the user location, i want it to go the the annotation region after the map is loaded, so i do this: 事情是,我不希望地图将区域/中心坐标设置为用户位置,我希望它在地图加载后进入注释区域,所以我这样做:

- (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];

}

So bottom line mapview outlet aint setting the region even tough the coordinates are fine. 因此,底线mapview出口甚至无法设定该区域的坐标就可以了。 it does however accept the different spans i gave it but its still always locked on the user region ; 但是它确实接受我给它的不同跨度,但是它仍然总是锁定在用户区; question is ...why? 问题是...为什么?

Its happen because your CLLocationManager class Update Location every time with your MKMapView so here your updated current location are set as region of your MapView 发生这种情况是因为您的CLLocationManager类每次都会使用MKMapView更新位置,因此在这里将您更新的当前位置设置为MapView的区域

For stop this ,just call this method.. 要停止此,只需调用此方法。

[yourLocationManager stopUpdatingLocation];

in your loadActiveEstateAnnotation method at starting. 在启动时在您的loadActiveEstateAnnotation方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM