美文网首页
地图小蓝点.

地图小蓝点.

作者: ViewController_ | 来源:发表于2018-07-28 22:53 被阅读0次

    导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

    相关文章

      网友评论

          本文标题:地图小蓝点.

          本文链接:https://www.haomeiwen.com/subject/endamftx.html