给一个简单事例注释很详细了应该不许要过多的解释了

//
//  ViewController.m
//  2014_11_03_大头针的使用
//
//  Created by Mac10.9 on 14-11-3.
//  Copyright (c) 2014年 xiaoxiaobing. All rights reserved.
//#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>#import "XXBAnnotation.h"@interface ViewController ()<CLLocationManagerDelegate , MKMapViewDelegate>@property (strong, nonatomic) CLLocationManager *locMgr;
@property (weak, nonatomic) IBOutlet MKMapView *mapView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self setupCLLocationManager];[self setupMapView];
}/***  懒加载*/
- (CLLocationManager *)locMgr
{if(![CLLocationManager locationServicesEnabled]){/**只有系统的定位功能是关闭的时候才会调用这个方法*/return nil;}if (!_locMgr){// 创建定位管理者self.locMgr = [[CLLocationManager alloc] init];// 设置代理self.locMgr.delegate = self;}return _locMgr;
}- (void)setupCLLocationManager
{// 开始定位用户的位置[self.locMgr requestAlwaysAuthorization];[self.locMgr startUpdatingLocation];}- (void)setupMapView
{// 1.跟踪用户位置(显示用户的具体位置)self.mapView.userTrackingMode = MKUserTrackingModeFollow;// 2.设置代理self.mapView.delegate = self;// 3.监听mapView的点击事件[self.mapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMapView:)]];
}- (void)tapMapView:(UITapGestureRecognizer *)tap
{// 1.获得用户在mapView点击的位置(x,y)CGPoint point = [tap locationInView:tap.view];// 2.将数学坐标 转为 地理经纬度坐标CLLocationCoordinate2D coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];// 3.创建大头针模型,添加大头针到地图上XXBAnnotation *anno = [[XXBAnnotation alloc] init];anno.coordinate = coordinate;anno.title = @"小小兵";anno.subtitle = @"小小兵的地盘";[self.mapView addAnnotation:anno];// 纬度范围:N 3°51′ ~  N 53°33′// 经度范围:E 73°33′ ~  E 135°05′for (int i = 0; i<1000; i++) {XXBAnnotation *anno = [[XXBAnnotation alloc] init];CLLocationDegrees latitude = 4 + arc4random_uniform(50);CLLocationDegrees longitude = 73 + arc4random_uniform(60);anno.coordinate = CLLocationCoordinate2DMake(latitude, longitude);anno.title = @"小小兵";anno.subtitle = @"小小兵的地盘";[self.mapView addAnnotation:anno];}
}#pragma mark - MKMapViewDelegate
/***  当用户的位置更新,就会调用(不断地监控用户的位置,调用频率特别高)**  @param userLocation 表示地图上蓝色那颗大头针的数据*/- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{userLocation.title = @"天朝帝都";userLocation.subtitle = @"是个非常牛逼的地方!";CLLocationCoordinate2D center = userLocation.location.coordinate;NSLog(@"%f %f", center.latitude, center.longitude);// 设置地图的中心点(以用户所在的位置为中心点)[mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];// 设置地图的显示范围MKCoordinateSpan span = MKCoordinateSpanMake(0.021321, 0.019366);MKCoordinateRegion region = MKCoordinateRegionMake(center, span);[mapView setRegion:region animated:YES];
}
/***  当地图的范围发生改变的时候会调用这个方法*/
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{/***  输出当前的地图的范围* latitudeDelta 维度* longitudeDelta 经度*/NSLog(@"%f %f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);
}/***  让用户的地点跑到屏幕中间*/
- (IBAction)backToUserLocation:(UIButton *)sender{[self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate animated:YES];
}
@end

MapKit 以及大头针的简单使用相关推荐

  1. iOS地图定位导航与大头针的简单使用

    定位 1.一次定位 1.创建位置管理器 // 这里创建的管理其对象如果没有强引用,就会造成你后面的操作不会出现效果,全局变量强引用.CLLocationManager *manager = [[CLL ...

  2. 开发知识点总结(期待你的评论)

    UI  主框架  1.利用UIScrollView+自定义UITbaleViewCell+UICollectionView进行主界面框架的搭建.  2.创建UINavigationController ...

  3. 使用TFHpple解析html

    https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 All) 将从github上下载 ...

  4. iOS 使用 socket 即时通信(非第三方库)

    其实写这个socket一开始我是拒绝的. 因为大家学C 语言和linux基础时肯定都有接触,客户端和服务端的通信也都了解过,加上现在很多开放的第三方库都不需要我们来操作底层的通信. 但是来了!!! 但 ...

  5. iOS 高德地图(二)(进阶具体使用的细节)

    2019独角兽企业重金招聘Python工程师标准>>> 前面我们配置好了SDK的环境,也在高德的官网中申请了AppKey:de5b39fb2b066ed80c51383bb3a1fe ...

  6. [文摘20070914]一个成功的博客必须知道的80个博客工具

    不管你的博客流量大小与否,不管你的博客主题是什么,只要你想成为一个成功的博客,下面的博客工具肯定会对你有所帮助. 一般的博客工具: Backupmyblog:自动备份你的博客数据,只对于mysql数据 ...

  7. 【iOS】Mapkit的使用:地图显示、定位、大头针、气泡等

    以前做项目用高德地图SDK,需要注册账号和AppID,然后下载SDK集成到项目中,比较麻烦,这几天看了下苹果自带的MapKit框架,感觉挺好用,官方文档也介绍得很详细,所以按照官方文档写了个demo, ...

  8. Core Location和MapKit的一些简单使用

    Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, s ...

  9. 第十章:使用MapKit开发地图服务

    一.使用MapKit框架 MapKit.framework使用MKMapView类代表地图控件,开发者只要在应用界面上添加并显示控件,该应用就可以增加地图. MapKitView类的常用属性如下: ( ...

最新文章

  1. web前端 vue、react、angular三大框架对比 与jquery的对比
  2. 【PP生产订单】入门介绍(八)
  3. linux socket原理,socket 的工作原理
  4. Docker实践4: 基于nginx对后端的weblogic负载均衡
  5. nginx+keepalived搭建主从负载均衡并迅速切换
  6. java程序日期转换_Java 日期转换详解及实例代码
  7. Linux文件系统不是必须的,而是必要的!
  8. 北京林业大学计算机科学与技术考研科目,北京林业大学计算机科学与技术考研经验-北林信息学院考研辅导班...
  9. matlab实验报告的总结,matlab实验报告
  10. 有关SQL Server 2008你一定要知道的八件事 之三
  11. C语言printf语法
  12. java游戏运行_用jar包运行带GUI的java游戏
  13. 编译libfetion时,提示 从 int 到 QString 的转换有歧义
  14. Python类的继承
  15. python+django+vue高校奖学金评定管理系统
  16. 【转载】Linux摄像头驱动1——vivid
  17. FLASH抽象层(FAL)程序的应用(rt-thread)
  18. 西门子S7-1200介绍和编程及博图软件的安装使用
  19. 稀疏数组(golang实现)
  20. 【JVM】 TLAB到底是干什么的

热门文章

  1. Vue Grid Layout -️ 适用Vue.js的栅格布局系统(保姆级使用教程)
  2. Mysql 配置同局域网下连接
  3. Python之操作Excel、异常处理、网络编程
  4. Mac 上文件名相同、大小写不同的文件夹会合并成一个所导致的问题
  5. Windows批处理文件/文件夹选择器对话框
  6. AidLearning设置中文界面和更换桌面主题
  7. 腾讯QQ大数据:神盾推荐——MAB算法应用总结
  8. spark 常用算子
  9. H5保持屏幕常亮方法-NoSleep插件
  10. 【开源项目】股票配资系统开发与设计