1:添加库CoreLocation.framework,MApKit.framework;

2:@property (nonatomic, strong) CLLocationManager *locationManager;

@property (nonatomic, strong) MKMapView *mapView;

@property (nonatomic, strong) CLLocation *checkinLocation;

@property (strong, nonatomic) NSString *currentLatitude; //纬度

@property (strong, nonatomic) NSString *currentLongitude; //经度

- (void)viewDidLoad {

[super viewDidLoad];

self.title=@"地图";

[self initRightBarButton];

[self setupLocationManager];

[self setupMapView];

}

-(void)initRightBarButton{

UIButton* _btnRight = [UIButton buttonWithType:UIButtonTypeCustom];

[_btnRight setFrame:CGRectMake(0, 0, 39, 34)];

UIImage *imgNormal = [UIImage imageNamed:@"gpsbtn_dianji"];

UIImage *imgSelect = [UIImage imageNamed:@"gpsbtn"];

[_btnRight setBackgroundImage:imgNormal forState:UIControlStateNormal];

[_btnRight setBackgroundImage:imgSelect forState:UIControlStateSelected];

_btnRight.showsTouchWhenHighlighted = YES;

[_btnRight addTarget:self action:@selector(showUserLocation:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:_btnRight];

self.navigationItem.rightBarButtonItem = buttonItem;

}

- (void)setupLocationManager{

_locationManager=[[CLLocationManager alloc]init];

_locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;

//每隔多少米定位一次(这里的设置为任何的移动)

_locationManager.distanceFilter=kCLDistanceFilterNone;

//iOS 8.0以后

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {

[self.locationManager requestWhenInUseAuthorization];

[self.locationManager startUpdatingLocation];

}

}

- (void)setupMapView{

_mapView=[[MKMapView alloc]initWithFrame:self.view.bounds];

[self.view addSubview:_mapView];

_mapView.delegate=self;

//用户位置追踪(用户位置追踪用于标记用户当前位置,此时会调用定位服务)

_mapView.userTrackingMode=MKUserTrackingModeFollowWithHeading;

_mapView.mapType=MKMapTypeStandard;

[self initLocationData];

}

- (void)initLocationData{

NSMutableArray *arr=[[NSMutableArray alloc]init];

for (int i=0; i<1; i++) {

CLLocationDegrees lat=[self.currentLatitude  doubleValue];

CLLocationDegrees longi=[self.currentLongitude doubleValue];

NSString *lacationName=@"当前位置";

BasicMapAnnotation *anno=[[BasicMapAnnotation alloc]initWithLatitude:lat andLongitude:longi];

anno.title=lacationName;

anno.index=i;

[arr addObject:anno];

}

[_mapView showAnnotations:arr animated:YES];

}

- (void)showUserLocation:(id)sender{

MKCoordinateSpan span=MKCoordinateSpanMake(0.01, 0.02);

MKCoordinateRegion region=MKCoordinateRegionMake(_mapView.userLocation.coordinate, span);

[_mapView setRegion:region animated:YES];

}

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

NSLog(@"纬度:%f 经度:%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

self.currentLatitude  = [NSString stringWithFormat:@"%.4f",userLocation.location.coordinate.latitude];

self.currentLongitude = [NSString stringWithFormat:@"%.4f",userLocation.location.coordinate.longitude];

[self initLocationData];

//设置地图显示范围(如果不进行区域设置会自动显示区域范围并指定当前用户位置为地图中心点)

//MKCoordinateSpan span=MKCoordinateSpanMake(0.01, 0.01);

//MKCoordinateRegion region=MKCoordinateRegionMake(_mapView.region.center, span);

//[_mapView setRegion:region animated:true];

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{

if ([annotation isKindOfClass:[BasicMapAnnotation class]]) {

static NSString *key=@"AnnotationKey";

MKAnnotationView *annotationView=[_mapView dequeueReusableAnnotationViewWithIdentifier:key];

BasicMapAnnotation *aa=(BasicMapAnnotation *)annotation;

if (!annotationView) {

annotationView=[[MKAnnotationView alloc]initWithAnnotation:aa reuseIdentifier:key];

CGRect frame=annotationView.frame;

frame.size.width=14;

frame.size.height=35;

annotationView.frame=frame;

annotationView.canShowCallout=YES;

UIImageView*imageview=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"地图标注"]];

imageview.frame=frame;

[annotationView addSubview:imageview];

}

return annotationView;

}

return nil;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}

原文:http://blog.csdn.net/darongzi1314/article/details/46624293

苹果系统地图定位服务器,iOS 系统地图实现及定位相关推荐

  1. 苹果屏蔽更新_屏蔽 iOS 系统更新的最新方法,支持所有 iPhone、iPad 设备

    为了进行功能性更新.封堵已知漏洞,苹果经常会推送 iOS 系统更新,但不是所有人都乐意将设备升级最新版.可是 iOS 中并未提供禁止更新的设定,因此,用户必须用各种手段达到屏蔽更新的目的. 在 202 ...

  2. iphone屏蔽系统更新_屏蔽 iOS 系统更新的最新方法,支持所有 iPhone、iPad 设备

    为了进行功能性更新.封堵已知漏洞,苹果经常会推送 iOS 系统更新,但不是所有人都乐意将设备升级最新版.可是 iOS 中并未提供禁止更新的设定,因此,用户必须用各种手段达到屏蔽更新的目的. 教程 阻断 ...

  3. 轻量服务器怎么换系统,轻量服务器更换系统

    轻量服务器更换系统 内容精选 换一换 包年包月镜像是基于按需镜像包装出的预付费套餐,一个包年包月镜像同一时间只能用于一台云服务器.包年包月镜像支持续费,在到期前用户可以选择续费继续使用.如果到期不对镜 ...

  4. ios如何设置系统定位服务器,ios怎么开定位服务器

    ios怎么开定位服务器 内容精选 换一换 Linux操作系统以主机板CMOS芯片的时间作为格林尼治标准时间,再根据设置的时区来确定系统的当前时间.但是一般Windows操作系统并不如此,Windows ...

  5. 苹果邮箱imap服务器,IOS系统IMAP邮箱设置

    IOS系统IMAP邮箱设置 第一步:进入设置界面然后选择"邮件.通讯录..."设置界面,然后选择"添加帐户",如下图: 第二步:在选择帐户类型界面中选择&quo ...

  6. ios文件连接 百度网盘服务器,iOS系统教程:iphone怎么解压百度网盘文件

    有很多网友问iphone手机(IOS系统)下载或者接收到的 zip/7z/rar等格式压缩包如何打开? 咱们讲过用IZIP软件可以操作,但是很多小伙伴不会操作,也有觉得操作过程太繁琐的.今天小编就再给 ...

  7. ios添加邮件收件服务器,iOS 系统邮件的基础使用

    尽管有好多人的主力邮件是 Gmail,客户端的首选也是 Gmail,但是在国内的互联网环境中不可避免的要使用到本土的一些邮件服务.对于这些轻量级的服务我选择用系统自带的邮件应用进行统一的管理.本文主要 ...

  8. 服务器双系统切换快捷键,服务器双系统同时开

    服务器双系统同时开 内容精选 换一换 云手机(Cloud Phone,简称CPH),是基于华为云裸金属服务器虚拟出的带有原生安卓操作系统,同时具有虚拟手机功能的云服务器.简单来说,云手机=云服务器+A ...

  9. 乐高无限自己地图无法服务器,乐高无限地图制作攻略 建造的小细节不要错过...

    哈喽!今天的小鹅在<乐高®无限>中,体验一把<街道垃圾大作战>地图,小鹅不仅要在市区收集垃圾,还要将它们投放到正确的垃圾箱中,Ε=(´ο`*)))挠头发,到底是谁在为难我小鹅! ...

最新文章

  1. 求长度的另一种方法(+obj).Length
  2. Nagios Web 页面声音报警
  3. android+点击屏幕隐藏键盘,Android点击EditText文本框之外任何地方隐藏键盘的解决办法...
  4. 组件化与插件化的差别在哪里?内含福利
  5. php 查文件sha1 内存不足,SHA是否足以检查文件重复? (PHP中的sha1_file)
  6. 转: SQLite内建函数表
  7. JavaScript异步加载与同步加载
  8. NUC1371 Who's in the Middle【中位数+排序】
  9. FCC算法题--Validate US Telephone Numbers
  10. php如何接受用户邮箱发送信息,怎么将用户购物车的产品发送到邮箱
  11. 文件已被占用的解决方法
  12. excel删除行闪退_excle2017打开就闪退:excel表格打开闪退怎么办
  13. 信号与线性系统管致中第六版pdf_第五讲 信号流图
  14. 计算机卸载不了360云盘,360企业云盘如何卸载?360企业云盘的四种卸载方法
  15. idea启动springboot项目控制台报错Command line is too long. Shorten command line for xxx or also for Spring B解决
  16. 【欣赏】一组唯美的图片
  17. 每日刷题:lightoj-1004 - Monkey Banana Problem
  18. 病原微生物高通量测序:第三节 检测原理
  19. Java程序的类体两部分_一般Java程序的类体由两部分组成:一部分是____,另一部分是____。...
  20. 5 张图带你理解 RocketMQ 消费者启动过程

热门文章

  1. R语言 ggplot2绘制双坐标轴(次坐标轴)
  2. 使用NSSM守护GeoServer、NetCore、Nginx的进程
  3. Cannot read field “parent“ because “comp“ is null
  4. TS无法找到模块“common.js”的声明文件
  5. 数据结构和算法(六)栈和队列
  6. interupt java_基于JDK8总结java中的interrupt
  7. 华为鸿蒙手表安装软件,能装“APP”的手表?华为鸿蒙手表平板来了!这钱要不要花?...
  8. c语言中从字中取高低字节,关于字节对齐
  9. Linux下编辑并保存文件操作步骤
  10. 国家大数据(贵州)综合试验区展示中心正式开馆