导MapKit.framework
#import "ViewController.h"
#import<Mapkit/Mapkit.h>
@interface ViewController ()<MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapview;
@property(nonatomic,strong)CLLocationManager *mgr;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//////Do any additional setup after loading the view, typically from a nib.
self.mgr=[CLLocationManager new];
//请求授权
if ([self.mgr respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.mgr requestWhenInUseAuthorization];
}
//跟踪用户
self.mapview.userTrackingMode=MKUserTrackingModeFollow;
self.mapview.delegate=self;
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{
//获取点击地图的点
CGPoint pint = [[touches anyObject]locationInView:self.mapview];
//将点击的点转换为经纬度
CLLocationCoordinate2D co2D= [self.mapview convertPoint:pint toCoordinateFromView:self.mapview];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString *identifier = @"cell";
// MKAnnotationView 没有
MKPinAnnotationView *mkView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!mkView) {
mkView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
mkView.pinTintColor=[UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1 ];
//设置掉落
mkView.animatesDrop=YES;
}
return mkView;
}
@end
&&&&&&&&&&info.plist里
Privacy - Location When In Use Usage Description
网友评论