iOS.定位服务与地图应用.05.跟踪用户位置变化

#import <UIKit/UIKit.h>

#import <MapKit/MapKit.h>



@interface T20140621000000ViewController : UIViewController<MKMapViewDelegate>



@property (weak, nonatomic) IBOutlet MKMapView *mapView;



@end
#import "T20140621000000ViewController.h"



@interface T20140621000000ViewController ()



@end



@implementation T20140621000000ViewController





- (void)viewDidLoad

{

    [super viewDidLoad];

    

    if ([CLLocationManager locationServicesEnabled])

    {

        _mapView.mapType = MKMapTypeStandard;

        _mapView.delegate = self;

        _mapView.showsUserLocation = YES;

        [_mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];

    }

}



- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}







#pragma mark -

#pragma mark Map View Delegate Methods

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

{

    _mapView.centerCoordinate = userLocation.location.coordinate;

}



- (void)mapViewDidFailLoadingMap:(MKMapView *)theMapView withError:(NSError *)error

{

    NSLog(@"error : %@",[error description]);

}





@end

 

你可能感兴趣的:(ios)