具体介和配置绍在此就不详述了,详情请看百度地图API文档,

在这里具体讲解下,新版百度地图的定位与反地理编码的使用:

1、导入头文件

#import <BaiduMapAPI_Map/BMKMapComponent.h>

#import <BaiduMapAPI_Location/BMKLocationComponent.h>

#import <BaiduMapAPI_Search/BMKSearchComponent.h>

2、设置代理

<

    BMKLocationServiceDelegate,

    BMKGeoCodeSearchDelegate

>

3、添加相关属性

@property (nonatomic, strong) BMKLocationService *locService;

@property (nonatomic, strong) BMKGeoCodeSearch *geoCode;        // 地理编码

@property (nonatomic, assign) CGFloat longitude;  // 经度

@property (nonatomic, assign) CGFloat latitude; // 纬度

4、开始写代码了

- (void)viewDidLoad {

    [super viewDidLoad];    

    [self startLocation];

}
- (void)startLocation
{
NSLog(@"进入普通定位态"); // 初始化BMKLocationService
_locService = [[BMKLocationService alloc]init];
_locService.delegate = self;
//启动LocationService
[_locService startUserLocationService];
} #pragma mark - CoreLocation 代理
#pragma mark 跟踪定位代理方法,每次位置发生变化即会执行(只要定位到相应位置)
//实现相关delegate 处理位置信息更新
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
NSLog(@"heading is %@",userLocation.heading);
} //处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
NSLog(@"当前位置信息:didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); self.longitude = userLocation.location.coordinate.longitude;
self.latitude = userLocation.location.coordinate.latitude; [self outputAdd];
// 当前位置信息:didUpdateUserLocation lat 23.001819,long 113.341650
} #pragma mark geoCode的Get方法,实现延时加载
- (BMKGeoCodeSearch *)geoCode
{
if (!_geoCode)
{
_geoCode = [[BMKGeoCodeSearch alloc] init];
_geoCode.delegate = self;
}
return _geoCode;
} //#pragma mark 获取地理位置按钮事件
- (void)outputAdd
{
// 初始化反地址编码选项(数据模型)
BMKReverseGeoCodeOption *option = [[BMKReverseGeoCodeOption alloc] init];
// 将数据传到反地址编码模型
option.reverseGeoPoint = CLLocationCoordinate2DMake(self.latitude, self.longitude);
NSLog(@"%f - %f", option.reverseGeoPoint.latitude, option.reverseGeoPoint.longitude);
// 调用反地址编码方法,让其在代理方法中输出
[self.geoCode reverseGeoCode:option];
} #pragma mark 代理方法返回反地理编码结果
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
if (result) {
// self.address.text = [NSString stringWithFormat:@"%@", result.address];
NSLog(@"位置结果是:%@ - %@", result.address, result.addressDetail.city);
// NSLog(@"经纬度为:%@ 的位置结果是:%@", locationString, result.address);
self.currentCityString = result.addressDetail.city; [self.cityButton setTitle:self.currentCityString forState:UIControlStateNormal];
// 定位一次成功后就关闭定位
[_locService stopUserLocationService]; }else{
NSLog(@"%@", @"找不到相对应的位置");
} } #pragma mark 代理方法返回地理编码结果
- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
if (result) {
NSString *locationString = [NSString stringWithFormat:@"经度为:%.2f 纬度为:%.2f", result.location.longitude, result.location.latitude];
NSLog(@"经纬度为:%@ 的位置结果是:%@", locationString, result.address);
// NSLog(@"%@", result.address);
}else{
// self.location.text = @"找不到相对应的位置";
NSLog(@"%@", @"找不到相对应的位置");
}
}

最后打印结果:

跟踪定位代理方法

当前位置信息:didUpdateUserLocation lat 23.001882,long 113.341635

2016-03-29 11:33:48.126 yrapp[5462:1995584] 23.001882 - 113.341635

 

代理方法返回地理编码结果

位置结果是:广东省广州市番禺区汉溪大道东 -

好了,新版百度地图API就这么简单,弄了半个小时才弄好,使用过程中如有问题,请联系本人

最新demo:详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`tabbar 的 消息栏目

微博:@博爱1616

QQ:137361770

## 3、博爱极力推荐

序号 | 类库 | 简介及功能介绍

:----------- | :-----------: | :-----------

3.1         | [『BAButton』](https://github.com/boai/BAButton)        | 完全实现 UIButton 的自定义的类库。pod 导入:`pod 'BAButton', '~> 1.0.1'`

3.2         | [pod安装和使用方法](http://www.cnblogs.com/boai/p/4977976.html)        | 对pod还是不熟的同学,可以看下我的博客,是最新的pod安装和使用方法,一直更新!

3.3         | [『BASegmentControl』](https://github.com/boai/BASegmentControl)        | 新增网易新闻的滑动SegmentControl,基于[『HMSegmentedControl』](https://github.com/HeshamMegid/HMSegmentedControl)的完美二次封装!

3.4         | [『BAReminderDemo』](https://github.com/boai/BAReminderDemo)        | 系统提醒和日历提醒,最近做了一个预约功能,有用到系统提醒和日历提醒,就写了这个demo!

3.5         | [『BALocalNotification』](https://github.com/boai/BALocalNotification)        | 本地通知最新完美封装,最近整理了下本地通知和极光推送,有很多坑都踩过了,刚刚整理出来的完美封装,肯定适合大部分场合,也可以用此封装写闹钟,也提醒事件,都可以!如果喜欢,请在git上点个星吧!

3.6         | [『BANetManager』](https://github.com/boai/BANetManager)        | 基于[『AFNetworking 3.1』](https://github.com/AFNetworking/AFNetworking)!最新版本的封装,集成了get/post 方法请求数据,单图/多图上传,视频上传/下载,网络监测 等多种网络请求方式!

3.7         | [『APP中的文字和APP名字的国际化多语言处理』](http://www.cnblogs.com/boai/p/5337558.html)        | 最全、最贴心的国际化处理博客!

3.8         | 3D Touch 的纯代码实现方法        | 详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`appdelegate`!

3.9         | [『DSAlert』](https://github.com/DS-Team/DSAlert-OC](https://github.com/DS-Team/DSAlert-OC)       | 目前为止,最为精简的 alert 和 actionSheet 封装!DSAlert 让你的弹框不再孤单![『DSAlert』](https://github.com/DS-Team/DSAlert-OC](https://github.com/DS-Team/DSAlert-OC)!

3.10        | 最新、最全、最优美的友盟登录和分享的封装        | 详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`demo 4`!

3.11        | 最新、最全、最优美的 清理 APP 缓存的封装        | 详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`demo 2`!

3.12        | 最新、最全、最优美的 渐变navi 的封装        | 详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`tabbar 的 消息栏目`!

3.13        | 最新、最全、最优美的 获取所有系统设置跳转 的封装        | 详见:[『BABaseProject』](https://github.com/boai/BABaseProject)中的`tabbar 的 消息栏目中demo 3`!

iOS 学习笔记五 【2016年百度地图定位详细使用方法】的更多相关文章

  1. Java web与web gis学习笔记(二)——百度地图API调用

    系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...

  2. android中百度地图定位的实现方法(仅适用于真机+WIFI联网环境)

    注意:此代码的环境是:真机(系统版本为Android4.2.2)+WIFI联网(才能实现最后的运行结果):使用虚拟机调试会出现各种问题. 第一步:下载SDK和申请Key 到百度的网站http://de ...

  3. iOS 学习笔记 五 (2015.03.17)使用storyBoard进行tableview的跳转

    方法一: 点击tableviewCell后,按住ctrl键拖拽至想要跳转的新的界面.这样跳转的结果是,点击tableview中的任何一行都会跳转到新的界面.可以通过控制cell的 属性 userInt ...

  4. IOS 学习笔记(6) 控件 文本域(UITextField)的使用方法

    UITextField控件的诸多特性都和UITextView相似,比如成为输入文本焦点时键盘自动显示,支持长按弹出动作选项,能够接收输入事件(开始输入,修改内容,结束输入和点击回车等). 1.特有的特 ...

  5. IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法

    相对于UILabell所支持的较短文本内容,UITextView对于长文本的支持更好.UITextView能够以滚动的方式全部浏览到长文本,并且就像UILabel那样,从ISO6,他也提供了对NSAt ...

  6. iOS学习笔记-地图MapKit入门

    代码地址如下:http://www.demodashi.com/demo/11682.html 这篇文章还是翻译自raywenderlich,用Objective-C改写了代码.没有逐字翻译,如有错漏 ...

  7. iOS 学习笔记七 【博爱手把手教你使用2016年gitHub Mac客户端】

    iOS 学习笔记七 [博爱手把手教你使用gitHub客户端] 第一步:首先下载git客户端 链接:https://desktop.github.com 第二步:fork 大神的代码[这里以我的代码为例 ...

  8. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

  9. iOS学习笔记总结整理

    来源:http://mobile.51cto.com/iphone-386851_all.htm 学习IOS开发这对于一个初学者来说,是一件非常挠头的事情.其实学习IOS开发无外乎平时的积累与总结.下 ...

随机推荐

  1. iOS 10 资料整理笔记

    1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserN ...

  2. Linux查看系统开机时间(转)

    1.who命令查看 who -b查看最后一次系统启动的时间. who -r查看当前系统运行时间 2.last  reboot last reboot可以看到Linux系统历史启动的时间. 重启一下操作 ...

  3. HDU 3389 Game(博弈)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. How to enable Hibernate option in windows 2008 R2 server?

    http://velshare.blogspot.com/2013/02/how-to-enable-hibernate-option-in.html 1) To enable the Hiberna ...

  5. java工具类获取properties文件的配置

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...

  6. 自定义WebViewPage,实现Url.Action生成绝对地址

    前言 运营部门一直对公司官网SEO有意见,认为做得不好(说得好像运营做不好都是seo似的).为此两部门老大还闹到CEO那去了. 也因为这事,工作计划终于排上日程.沟通一番后得知有如下几点需求: 1.所 ...

  7. Android ProgressBar手动控制开始和停止

    这两天有个需求,点击按钮从SD卡解压压缩包,并读取压缩包内txt文档内容,然后在街面上显示出来.毕竟IO操作很耗时,如果文件较大会花费不少时间.所以,在处理数据的时候能给个进度就好了.我们通常的做法就 ...

  8. css自动换行与不换行

    1.自动换行 div{ word-wrap: break-word; word-break: normal; } 2.不换行 div{ white-space:nowrap; } 3.浮动效果不换行 ...

  9. Kubernetes Fluentd+Elasticsearch+Kibana统一日志管理平台搭建的填坑指南

    在初步完成Kubernetes集群架构的建立后,通过搭建一些监控组件,我们已经能够实现 图形化的监控每个node,pod的状态信息和资源情况 通过scale进行replicateSet的扩展和伸缩 通 ...

  10. LibreOffice创建数据透视表

    LibreOffice创建数据透视表 LibreOffice: 选中数据,Data->Pivot Table->Create,拖拽行.列到Row和column,Data Filed要点击O ...