Objective-c - 当地图更新自己时,停止集中用户位置

时间:2012-04-18 10:48:17

标签: ios

我使用MapKit框架创建了一个简单的应用程序。启动时,用户位置会放大并显示。但是当我缩小并在地图上滚动时,它会在几秒钟后自动将其自我集中到用户位置。我怎么能阻止这个?

在m文件中:

#import "APPNAMEViewController.h"
#import <MapKit/MapKit.h>

@synthesize mapview;

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)aUserLocation     {
    mapView.scrollEnabled = YES;
    mapView.zoomEnabled = YES;
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta = 0.005;
    span.longitudeDelta = 0.005;
    CLLocationCoordinate2D location;
    location.latitude = aUserLocation.coordinate.latitude;
    location.longitude = aUserLocation.coordinate.longitude;
    region.span = span;
    region.center = location;
    [mapView setRegion:region animated:NO];
    [mapView setUserTrackingMode:MKUserTrackingModeNone animated:NO];
}
- (void)viewDidLoad
{
     [super viewDidLoad];
     mapview = [[MKMapView alloc]
           initWithFrame:CGRectMake(0,
                                    44,
                                    self.mapview.bounds.size.width,
                                    self.mapview.bounds.size.height)
           ];
     mapview.showsUserLocation = YES;
     mapview.mapType = MKMapTypeStandard;
     mapview.delegate = self;
     [mapview setUserTrackingMode:MKUserTrackingModeNone animated:NO];

     [self.view addSubview:mapview];
}

请帮帮我:)。

祝你好运 米甲

3 个答案:

答案 0 :(得分:0)

删除[mapView setRegion:region animated:NO];

中的- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)aUserLocation

答案 1 :(得分:0)

[mapView setRegion:region animated:NO]; //Changes the currently visible region and optionally animates the change.

答案 2 :(得分:0)

删除:[mapView setUserTrackingMode:MKUserTrackingModeNone animated:NO];

这使地图中心位于当前位置。