重要:为进一步采取加强对最终用户个人信息的安全保护措施,从定位SDK v2.0.2版本起,请开发者务必确保调用SDK任何接口前先调用隐私合规接口setAgreePrivacy,否则可能会无法正常使用相关功能。具体可参考开发指南-注册和获取秘钥-iOS定位SDK隐私合规接口。
#import <BMKLocationKit/BMKLocationComponent.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK[[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"您的AK" authDelegate:self];return YES;}BMKLocationManager *locationManager = [[BMKLocationManager alloc] init];locationManager.delegate = self;locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;locationManager.distanceFilter = kCLDistanceFilterNone;locationManager.desiredAccuracy = kCLLocationAccuracyBest;locationManager.activityType = CLActivityTypeAutomotiveNavigation;locationManager.pausesLocationUpdatesAutomatically = NO;locationManager.allowsBackgroundLocationUpdates = YES;locationManager.locationTimeout = 10;locationManager.reGeocodeTimeout = 10;[locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {//获取经纬度和该定位点对应的位置信息}];
#import <BMKLocationKit/BMKLocationComponent.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK[[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"您的AK" authDelegate:self];return YES;}BMKLocationManager *locationManager = [[BMKLocationManager alloc] init];locationManager.delegate = self;locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;locationManager.distanceFilter = kCLLocationAccuracyBestForNavigation;locationManager.desiredAccuracy = kCLLocationAccuracyBest;locationManager.activityType = CLActivityTypeAutomotiveNavigation;locationManager.pausesLocationUpdatesAutomatically = NO;locationManager.allowsBackgroundLocationUpdates = NO;// YES的话是可以进行后台定位的,但需要项目配置,否则会报错,具体参考开发文档locationManager.locationTimeout = 10;locationManager.reGeocodeTimeout = 10;//开始定位[locationManager startUpdatingLocation];//结束定位//[locationManager stopUpdatingLocation];#pragma mark - BMKLocationManagerDelegate/*** @brief 连续定位回调函数。* @param manager 定位 BMKLocationManager 类。* @param location 定位结果,参考BMKLocation。* @param error 错误信息。*/- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didUpdateLocation:(BMKLocation * _Nullable)location orError:(NSError * _Nullable)error{}/*** @brief 该方法为BMKLocationManager提供设备朝向的回调方法。* @param manager 提供该定位结果的BMKLocationManager类的实例* @param heading 设备的朝向结果*/- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)managerdidUpdateHeading:(CLHeading * _Nullable)heading{}
#import <BMKLocationKit/BMKLocationComponent.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK[[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"您的AK" authDelegate:self];return YES;}BMKLocationManager *locationManager = [[BMKLocationManager alloc] init];locationManager.delegate = self;locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;locationManager.distanceFilter = kCLLocationAccuracyBestForNavigation;locationManager.desiredAccuracy = kCLLocationAccuracyBest;locationManager.activityType = CLActivityTypeAutomotiveNavigation;locationManager.pausesLocationUpdatesAutomatically = NO;locationManager.allowsBackgroundLocationUpdates = YES;// YES的话是可以进行后台定位的,但需要项目配置,否则会报错,具体参考开发文档locationManager.locationTimeout = 10;locationManager.reGeocodeTimeout = 10;//开始定位[locationManager startUpdatingLocation];//结束定位//[locationManager stopUpdatingLocation];#pragma mark - BMKLocationManagerDelegate/*** @brief 连续定位回调函数。* @param manager 定位 BMKLocationManager 类。* @param location 定位结果,参考BMKLocation。* @param error 错误信息。*/- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didUpdateLocation:(BMKLocation * _Nullable)location orError:(NSError * _Nullable)error{}/*** @brief 该方法为BMKLocationManager提供设备朝向的回调方法。* @param manager 提供该定位结果的BMKLocationManager类的实例* @param heading 设备的朝向结果*/- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)managerdidUpdateHeading:(CLHeading * _Nullable)heading{}
#import <BMKLocationKit/BMKLocationComponent.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK[[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"您的AK" authDelegate:self];return YES;}BMKLocationManager *locationManager = [[BMKLocationManager alloc] init];locationManager.delegate = self;locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;locationManager.distanceFilter = kCLDistanceFilterNone;locationManager.desiredAccuracy = kCLLocationAccuracyBest;locationManager.activityType = CLActivityTypeAutomotiveNavigation;locationManager.pausesLocationUpdatesAutomatically = NO;locationManager.allowsBackgroundLocationUpdates = YES;locationManager.locationTimeout = 10;locationManager.reGeocodeTimeout = 10;[locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {}];
#import <BMKLocationKit/BMKLocationComponent.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 需要注意的是请在 SDK 任何类的初始化以及方法调用之前设置正确的 AK[[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"您的AK" authDelegate:self];return YES;}#import <BaiduMapAPI_Base/BMKBaseComponent.h>#import <BaiduMapAPI_Map/BMKMapComponent.h>BMKMapView *mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];//设置mapView的代理mapView.delegate = self;//将mapView添加到当前视图中[self.view addSubview:mapView];BMKGeoFenceManager *geofenceManager = [[BMKGeoFenceManager alloc] init];geofenceManager.delegate = self;geofenceManager.pausesLocationUpdatesAutomatically = NO;geofenceManager.allowsBackgroundLocationUpdates = YES;CLLocationCoordinate2D centerGeofence = CLLocationCoordinate2DMake(39.914682, 116.403898); //天安门BMKPointAnnotation *pointAnnotation = [[BMKPointAnnotation alloc]init];pointAnnotation.coordinate = centerGeofence;pointAnnotation.title = @"圆形地理围栏";[mapView removeAnnotations:mapView.annotations];[mapView addAnnotation:pointAnnotation];BMKCircle* circle = [BMKCircle circleWithCenterCoordinate:_ centerGeofence radius: 100];[mapView addOverlay:circle];geofenceManager.activeAction = BMKGeoFenceActiveActionStayed | BMKGeoFenceActiveActionInside | BMKGeoFenceActiveActionOutside;[geofenceManager addCircleRegionForMonitoringWithCenter:centerGeofence radius:100 coorType:BMKLocationCoordinateTypeBMK09LL customID:@"circle_1"];#pragma mark - BMKMapViewDelegate/***根据anntation生成对应的View*@param mapView 地图View*@param annotation 指定的标注*@return 生成的标注View*/- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation{//普通annotationNSString *AnnotationViewID = @"renameMark";BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];if (annotationView == nil) {annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];// 设置颜色annotationView.pinColor = BMKPinAnnotationColorPurple;// 从天上掉下效果annotationView.animatesDrop = YES;// 设置可拖拽annotationView.draggable = YES;}return annotationView;}/***根据overlay生成对应的View*@param mapView 地图View*@param overlay 指定的overlay*@return 生成的覆盖物View*/- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{if ([overlay isKindOfClass:[BMKCircle class]]){BMKCircleView* circleView = [[BMKCircleView alloc] initWithOverlay:overlay];circleView.fillColor = [[UIColor alloc] initWithRed:1 green:0 blue:0 alpha:0.1];circleView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.5];circleView.lineWidth = 2.0;return circleView;}return nil;}
下一篇
本篇文章对您是否有帮助?