IOS 百度地图定位,显示地理位置
来源:互联网 发布:山大2017网络教育答案 编辑:程序博客网 时间:2024/05/24 01:49
最近公司要做一个类似与美团的东西,让我用百度地图来进行定位,并显示地理信息.
那么我们要如何做呢,直接上代码
- 先看看包结构,要把需要用到的库都要引入进来.
注意:appdelegate.mm 后缀一定要加个m
不然的话编译会不通过,好像是因为它的编译原理是c++还是怎样,要详细了解的可以百度. - 那么来看控制器代码
_locService = [[BMKLocationService alloc]init];//定位功能的初始化 _locService.delegate = self;//设置代理位self //启动LocationService [_locService startUserLocationService];//启动定位服务 _geocodesearch = [[BMKGeoCodeSearch alloc] init]; //编码服务的初始化(就是获取经纬度,或者获取地理位置服务) _geocodesearch.delegate = self;//设置代理为self
这段代码需要放在viewDidLoad里面
启动定位服务后,_locService.userLocation.location.coordinate就应该会有值了,也就是说经度和纬度都可以获取出来了.
- 开始定位的点击事件,将刚刚定位的经纬度取出来并设置lable的值
-(void)heheda:(UIButton *)btn{ NSLog(@"进入普通定位态"); NSLog(@"定位的经度:%f,定位的纬度:%f",_locService.userLocation.location.coordinate.longitude,_locService.userLocation.location.coordinate.latitude); self.lon.text = [NSString stringWithFormat:@"%f",_locService.userLocation.location.coordinate.longitude]; [self.lat setText:[NSString stringWithFormat:@"%f",_locService.userLocation.location.coordinate.latitude]];}
- 获取地址的点击事件
-(void)onClickReverseGeocode //发送反编码请求的.{ isGeoSearch = false; CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0, 0};//初始化 if (_locService.userLocation.location.coordinate.longitude!= 0 && _locService.userLocation.location.coordinate.latitude!= 0) { //如果还没有给pt赋值,那就将当前的经纬度赋值给pt pt = (CLLocationCoordinate2D){_locService.userLocation.location.coordinate.latitude, _locService.userLocation.location.coordinate.longitude}; } BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];//初始化反编码请求 reverseGeocodeSearchOption.reverseGeoPoint = pt;//设置反编码的店为pt BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];//发送反编码请求.并返回是否成功 if(flag) { NSLog(@"反geo检索发送成功"); } else { NSLog(@"反geo检索发送失败"); }}
如果发送成功,百度将会返回东西给你,然后你可以在下面这个代理函数中处理
-(void) onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{ if (error == 0) { BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init]; item.coordinate = result.location; item.title = result.address; NSString* titleStr; NSString* showmeg; titleStr = @"反向地理编码"; showmeg = [NSString stringWithFormat:@"%@",item.title]; self.addr.text = showmeg; UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:titleStr message:showmeg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",nil]; [myAlertView show]; }}
有不明白的还是可以下载demo来看看,记得点个star哦
https://github.com/ouzhenxuan/baiduMap
如果喜欢请给个赞.
文/区振轩(简书作者)
原文链接:http://www.jianshu.com/p/dc18c6b5be8b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
原文链接:http://www.jianshu.com/p/dc18c6b5be8b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
0 0
- IOS 百度地图定位,显示地理位置
- IOS 百度地图定位,显示地理位置
- 原始经纬度转百度地图定位并显示地理位置
- 利用百度地图的API定位地理位置
- android 定位 获取地理位置 百度地图
- 百度地图定位显示
- iOS百度地图定位
- iOS 百度地图反编码地理位置信息
- iOS之百度地图获取地理位置名称
- iOS 百度地图定位不显示蓝色小圆圈
- 【百度地图api】之获取当前用户地理位置-浏览器定位
- IOS 百度地图定位一片空白
- IOS百度地图定位总结
- ios 百度地图定位
- ios百度地图定位实现
- 浏览器定位之 - 百度定位地图显示
- 百度地图的定位+地图显示总结
- 百度地图定位地图不显示
- 第二课:ARM底层开发笔记之裸机程序开发
- Hibernate 中遇到Member类执行查询、更新、删除会出错
- SpringMVC中从一个控制器方法跳转到另一个控制器方法(亲测)
- selenium结合sikuli实现百度的图片搜索功能
- Linux开机自启动总结
- IOS 百度地图定位,显示地理位置
- 100. Same Tree
- c#开发_Dev的关于XtraGrid的使用(GridControl小结)_First
- 【Eclipse】--修改项目访问地址头
- 顺序表增强
- js格式化日期函数
- 推送通知自定义提示声音
- 使用Eclipse构建Maven项目 (step-by-step)
- (01)JS大法好,JavaScript一统天下开篇