iOS开发-开发百度地图2-iOS SDK 3.0.0-定位及geo检索服务
来源:互联网 发布:高中免费教学视频软件 编辑:程序博客网 时间:2024/06/08 00:27
四、定位功能
由于系统原因,iOS不允许使用第三方定位,因此地图SDK中的定位方法,本质上是对原生定位的二次封装。通过封装,开发者可更便捷的使用。此外,地图SDK中还提供了相应的定位图层(支持定位三态效果),帮助开发者显示当前位置信息。
注:自iOS8起,系统定位功能进行了升级,SDK为了实现最新的适配,自v2.5.0起也做了相应的修改,开发者在使用定位功能之前,需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):
NSLocationWhenInUseUsageDescription ,允许在前台使用时获取GPS的描述
NSLocationAlwaysUsageDescription ,允许永久使用GPS的描述
1、签协议,声明属性
@interface YMMapViewController
<BMKLocationServiceDelegate,BMKMapViewDelegate>@property (nonatomic,retain)BMKLocationService *locService;
@property (nonatomic,retain)BMKMapView *mapView;
2、具体实现
- (void)viewDidLoad {
[superviewDidLoad];
_mapView = [[BMKMapViewalloc]initWithFrame:CGRectMake(0,0,320,480)];
_mapView.trafficEnabled =YES;
// 设置路况信息
self.view =_mapView;
// 设置地图的比例
_mapView.zoomLevel =20;
// 设置地图旋转角度
_mapView.rotation =50;
_locService = [[BMKLocationServicealloc]init];
_locService.delegate =self;
//启动LocationService
[_locServicestartUserLocationService];
}
//实现相关delegate处理位置信息更新
//定位成功处理方法
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
_mapView.showsUserLocation =YES;//显示定位图层
[_mapViewupdateLocationData:userLocation];
_mapView.centerCoordinate = userLocation.location.coordinate;
// 设置地图比例
_mapView.zoomLevel =20;
}
//定位失败处理方法
- (void)didFailToLocateUserWithError:(NSError *)error{
UIAlertView* alert = [[UIAlertViewalloc]
initWithTitle:@"提示"
message:@"定位失败,请设置允许软件开始定位"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}
-(void)viewWillDisappear:(BOOL)animated {
[superviewWillDisappear:animated];
[_mapViewviewWillDisappear];
_mapView.delegate =nil;// // 此处记得不用的时候需要置nil,否则影响内存的释放
_locService.delegate =nil;
}
- (void)viewWillAppear:(BOOL)animated {
[superviewWillAppear:animated];
[_mapViewviewWillAppear];
_mapView.delegate =self;// 此处记得不用的时候需要置nil,否则影响内存的释放
_locService.delegate =self;
}
五、geo检索服务
1、签协议,声明属性
<BMKGeoCodeSearchDelegate>{
BMKGeoCodeSearch* _geocodesearch;
}
_geocodesearch = [[BMKGeoCodeSearchalloc]init];
_geocodesearch.delegate = self;
2、在定位成功的方法里调用此方法
//定位成功方法
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation;
- (void)nowPlace{
isGeoSearch =false;
CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0,0};
pt = (CLLocationCoordinate2D){_mapView.centerCoordinate.latitude ,_mapView.centerCoordinate.longitude};
BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOptionalloc]init];
reverseGeocodeSearchOption.reverseGeoPoint = pt;
BOOL flag = [_geocodesearchreverseGeoCode:reverseGeocodeSearchOption];
if(flag)
{
NSLog(@"反geo检索发送成功");
}
else
{
NSLog(@"反geo检索发送失败");
}
}
#pragma mark - BMKGeoCodeSearchDelegate协议方法
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
BMKAddressComponent *addressComponent = result.addressDetail;
NSString *title = [NSStringstringWithFormat:@"%@%@%@%@", addressComponent.city, addressComponent.district, addressComponent.streetName, addressComponent.streetNumber];
NSLog(@"%s -- %@",__func__, title);
}
- iOS开发-开发百度地图2-iOS SDK 3.0.0-定位及geo检索服务
- iOS开发-开发百度地图1-iOS SDK 3.0.0-基本地图的配置及实现
- iOS百度地图poi检索(基于百度地图2.3.0SDK开发)
- iOS百度地图集成时反geo 检索发送失败和geo 检索发送失败
- iOS开发 - 百度地图后台持续定位
- iOS开发 - 百度地图后台持续定位
- iOS开发百度地图SDK集成方法
- ios百度导航SDK,iOS开发之百度地图导航
- iOS开发地图定位及地理编码
- 【iOS】iOS开发中,如何使用百度地图SDK!
- IOS开发百度地图
- IOS百度地图开发
- iOS开发 - 百度地图
- iOS 开发 百度地图
- 使用百度地图SDK反geo检索失败的问题
- iOS开发 - 解决百度地图模拟器无法定位问题
- 百度地图iOS SDK开发教程(珍藏版)
- iOS开发——百度地图SDK集成
- 中华万年历 1.42版本已发布
- java中的逻辑运算符与位运算符
- cocos2dx LUA 读取本地JSON文件
- Jmeter--响应断言
- 建议77: 正确停止线程
- iOS开发-开发百度地图2-iOS SDK 3.0.0-定位及geo检索服务
- liunx基础
- Mybatis动态拼接SQL
- SQL连接查询
- synchronized与线程管理
- Netty/NIO实践
- C语言内置宏
- 神经网络资料整理
- 微擎 拼团支付提示URL 未注册