#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController () <CLLocationManagerDelegate, MKMapViewDelegate>
@property (strong, nonatomic) CLLocationManager *manager;
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.manager requestAlwaysAuthorization];
NSLog(@"%@", [MKMapView class]);
self.mapView.userTrackingMode = MKUserTrackingModeFollow;
}
#pragma mark - MKMapViewDelegate
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocation *location = userLocation.location;
NSLog(@"%f, %f", location.coordinate.latitude, location.coordinate.longitude);
NSLog(@"%@", userLocation.title);
}
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
NSLog(@"地图加载完成后触发");
}
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
NSLog(@"地图显示区域即将改变触发");
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
NSLog(@"地图显示区域改变之后触发");
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"授权成功");
}
}
#pragma mark - Getter & Setter
- (CLLocationManager *)manager
{
if ( !_manager) {
_manager = [[CLLocationManager alloc] init];
_manager.delegate = self;
}
return _manager;
}
@end