如何在iOS 8中制作显示位置的按钮



这似乎是一个非常基本的问题,但我什么都没找到,我已经试过了!!我只想做一个按钮放大到用户的位置!这就是我目前所掌握的:

CLLocationCoordinate2D userLocationCoordinate;
- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        [self.locationmanager requestWhenInUseAuthorization];}
    [locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
    NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
    userLocationCoordinate.latitude = newLocation.coordinate.latitude;
    userLocationCoordinate.longitude = newLocation.coordinate.longitude;
}
-(IBAction)showUserLocation:(id)sender{
    [self.mapview setCenterCoordinate:userLocationCoordinate animated:YES];
}

求你了,我需要帮助,如果有办法我不用CLLocationManager会更好。

谢谢。

您仍然需要CLLocationManager向用户请求位置权限,但是您可以使用MKMapViewsetUserTrackingMode方法来要求地图视图以用户的位置为中心。

如果您不想在用户移动时继续更新地图位置,则应将跟踪模式设置为Follow,几秒钟后再将其设置为None

相关内容

  • 没有找到相关文章

最新更新