糖果派对官方网站_可以赌钱的糖果游戏_手机版
百度地图后台定位解决方法

百度地图后台定位解决方法

作者:网络编程    来源:未知    发布时间:2020-04-26 20:10    浏览量:

1.//开启后台定位

#import"LYJ_BMKDemoController.h"

直接复制粘贴走不谢

self.service.allowsBackgroundLocationUpdates = YES;

#import"DFS_NetworkTool.h"

2.

#import

appdelegate.h 文件


#import#import@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@property (nonatomic, strong) BMKMapManager *mapManager;

@property (nonatomic, strong) UINavigationController *navigationController;

@end

本土图片,请重新上传

#import

appdelegate.m 文件


#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.mapManager = [[BMKMapManager alloc]init];

BOOL ret = [_mapManager start:@"ZDWvBohcN1G7cQUvid5rj1D7P1ilHAe0"  generalDelegate:nil];

if (!ret) {

NSLog(@"manager start failed!");

}

[self.window addSubview:self.navigationController.view];

[self.window makeKeyAndVisible];

return YES;

}

3.①NSLocationWhenInUseUsageDescription ②Required background modes ③App registers for location updates

#import"LYJ_SotreInfoModel.h"

viewcontroller.m文件


#import "ViewController.h"

#import<BaiduMapAPI_Map/BMKMapComponent.h>//引进地图功用全部的头文件

#import<BaiduMapAPI_Location/BMKLocationComponent.h>//引进定位功效有着的头文件

#import<BaiduMapAPI_Search/BMKRouteSearch.h>

#import "SVProgressHUD.h"

#import<BaiduMapAPI_Base/BMKTypes.h>

#import<BaiduMapAPI_Utils/BMKGeometry.h>

@interface ViewController ()<BMKMapViewDelegate,BMKRouteSearchDelegate,BMKLocationServiceDelegate>

@property (nonatomic, strong)BMKMapView *mapView;

@property (nonatomic, strong)BMKRouteSearch *routeSearch;

@property (nonatomic, strong)BMKLocationService *locService;

@property (nonatomic, strong)BMKUserLocation *userLocation;

@property (nonatomic, strong)BMKPolyline* polyline;

@property(nonatomic,weak)UIButton *backBtn;

@property(nonatomic,weak)UILabel *distanceLabel;

@end

@implementation ViewController

/**

全部流程: 开启实时平昔-->每一趟获得顾客地方-->央求步行路径-->拆解解析-->在地形图上画线

*/

- (void)viewDidLoad {

[super viewDidLoad];

BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

_mapView =mapView;

self.view = mapView;

//1. 定位

_mapView.showsUserLocation = YES;//显示定位图层

//初始化BMKLocationService

_locService = [[BMKLocationService alloc]init];

_locService.delegate = self;

//启动LocationService

[_locService startUserLocationService];

_mapView.userTrackingMode = BMKUserTrackingModeFollow;

//那一个button用于回到当前地点

[self setupBtn];

}

- (void)setupBtn{

UIButton *backBtn = [UIButton new];

[backBtn setTitle:@"回到当前地点" forState:UIControlStateNormal];

[backBtn setImage:[UIImage imageNamed:@"tabbar_compose_background_icon_return"] forState:UIControlStateNormal];

[backBtn sizeToFit];

[self.mapView addSubview:backBtn];//62 135 47

backBtn.titleLabel.font = [UIFont boldSystemFontOfSize:13];

backBtn.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 150, 50, 150, 50);

[backBtn setTitleColor:[UIColor colorWithRed:62/255.0 green:135/255.0 blue:47/255.0 alpha:1] forState:UIControlStateNormal];

[backBtn addTarget:self action:@selector(goToUserLocation:) forControlEvents:UIControlEventTouchUpInside];

_backBtn = backBtn;

_backBtn.hidden = YES;

UILabel *distanceLabel = [[UILabel alloc]init];

distanceLabel.text = @"miiii";

[self.mapView addSubview:distanceLabel];

_distanceLabel = distanceLabel;

distanceLabel.frame = CGRectMake(self.mapView.center.x, self.mapView.center.y - 200, 200, 50);

}

//3. 剖析路线, 画图

-百度地图后台定位解决方法。 (void)onGetWalkingRouteResult:(BMKRouteSearch*)searcher result:(BMKWalkingRouteResult*)result errorCode:(BMKSearchErrorCode)error{

if (error) {

NSLog(@"%u",error);

}else{

BMKRouteLine *line = result.routes[0];

_distanceLabel.text = [NSString stringWithFormat:@"%d",line.distance];

int count = 0;

for (int i = 0; i < line.steps.count; i++) {

BMKWalkingStep* step = line.steps[i];

count += step.pointsCount;

}

CLLocationCoordinate2D coors[count];

int count2 = 0;

for (int i = 0; i < line.steps.count; i++) {

BMKWalkingStep* step = line.steps[i];

for (int j = 0; j < step.pointsCount; j++) {

BMKMapPoint p = step.points[j];

//            NSLog(@"%f, %f", p.x, p.y);

CLLocationCoordinate2D annotationCoord = BMKCoordinateForMapPoint(p);

coors[count2] = annotationCoord;

count2++;

}

}

if (self.polyline) {

[self.mapView removeOverlays:self.mapView.overlays];

}

self.polyline = [BMKPolyline polylineWithCoordinates:coors count:count];

[_mapView addOverlay:_polyline];

}

}

//重临自定义的门路线条样式- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id)overlay{

if ([overlay isKindOfClass:[BMKPolyline class]]){

BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];

polylineView.strokeColor = [[UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1] colorWithAlphaComponent:0.8];

polylineView.lineWidth = 3.0;

[SVProgressHUD dismiss];

self.backBtn.hidden = NO;

return polylineView;

}

return nil;

}

//2. 甩卖地方坐标更新

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

//    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

[_mapView updateLocationData:userLocation];

self.userLocation = userLocation;

//    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];

//    annotation.coordinate = userLocation.location.coordinate;

//    annotation.title = @"这里是...";

//    [_mapView addAnnotation:annotation];

//

self.routeSearch = [[BMKRouteSearch alloc]init];

_routeSearch.delegate = self;

BMKPlanNode *start = [[BMKPlanNode alloc]init];

start.pt = self.userLocation.location.coordinate;

BMKPlanNode *end = [[BMKPlanNode alloc]init];

end.pt = CLLocationCoordinate2DMake(31.17034,121.412371);

BMKWalkingRoutePlanOption *option = [[BMKWalkingRoutePlanOption alloc]init];

option.from = start;

option.to = end;

//发起步行路线检索(检索成功后会调用代理方法"onGetWalkingRouteResult..."卡塔尔

BOOL res = [self.routeSearch walkingSearch:option];

NSLog(@"res = %d", res);

if (self.polyline == nil) {//第三遍加载地图时间比较长, 使用HUD, 后边不再使用.

[SVProgressHUD showWithStatus:@"路径加载中"];

}

}

-(void)viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];

}

//这里可以自定义顾客Logo//- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id)annotation

//{

//    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {

//        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];

//        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;

//        newAnnotationView.animatesDrop = YES;// 设置该标注点动漫展现

//        return newAnnotationView;

//    }

//    return nil;

//}

-(void)viewWillAppear:(BOOL)animated

{

[_mapView viewWillAppear];

_mapView.delegate = self; // 此处记得不要的时候须求置nil,否则影响内部存款和储蓄器的假释

}

-(void)viewWillDisappear:(BOOL)animated

{

[_mapView viewWillDisappear];

_mapView.delegate = nil; // 不用时,置nil

}

-(void)goToUserLocation:(id)sender {

[self.mapView setCenterCoordinate:self.userLocation.location.coordinate];

}

@end

本土图片,请重新上传

#import"LYJ_PointAnnotaion.h"

//在那处成立的单例类,整个工程都得以选用,开启和固定

@interfaceLYJ_BMKDemoController()

#import "LocationManager.h"

@property(nonatomic,strong)BMKMapView* mapView;

#import "SQLManager.h"

@property(nonatomic,strong)BMKLocationService* locService;

#import "ZYPoint.h"

@property(nonatomic,strong)UITableView* tableView;

#define UPLOAD_TRACEURL @""

@property(nonatomic,strong)NSMutableArray* dataSoure;

@implementation LocationManager

@end

static LocationManager *manager = nil;

@implementationLYJ_BMKDemoController

static BMKMapView *mapView = nil;

-(void)viewWillAppear:(BOOL)animated{

static NSMutableDictionary*tempDic = nil;

[_mapViewviewWillAppear];

static NSMutableArray*_togetherArr = nil;

_mapView.delegate=self;// 此处记得不要的时候需求置nil,不然影响内部存款和储蓄器的放出

static NSMutableDictionary*dic = nil;

_locService.delegate=self;

//成立单例类

}

+(LocationManager *)manager

-(void)viewWillDisappear:(BOOL)animated{

{

[_mapViewviewWillDisappear];

if

_mapView.delegate=nil;// 不用时,置nil

{

_locService.delegate=nil;

manager = [[LocationManager alloc] init];

}

tempDic=[[NSMutableDictionary alloc]initWithCapacity:0];

- (void)viewDidLoad {

_togetherArr=[[NSMutableArray alloc]init];

[superviewDidLoad];

dic=[[NSMutableDictionary alloc]initWithCapacity:0];

[self addBMKMapView];

}

[self addTabelView];

return manager;

}

}

-(void)addBMKMapView{

- init

self.navigationItem.title=@"LYJ_BMPDemo";

{

_mapView= [[BMKMapView alloc] init];

self = [super init];

[self.view addSubview:_mapView];

if

_mapView.frame=CGRectMake(0,64,self.view.bounds.size.width,self.view.bounds.size.height/2);

{

_locService= [[BMKLocationService alloc]init];

self.service= [[BMKLocationService alloc] init];

[_locService startUserLocationService];

self.service.distanceFilter = 10;

_mapView.userTrackingMode=BMKUserTrackingModeFollow;//设置一定的情况为平常定位方式

self.service.delegate = self;

_mapView.showsUserLocation=YES;

//开启后台定位

self.mapView.zoomLevel=18;

self.service.allowsBackgroundLocationUpdates = YES;

}

//开启定位

-(void)addTabelView{

[self.service startUserLocationService];

[self.view addSubview:self.tableView];

}

CGFloatheight = [UIScreenmainScreen].bounds.size.height-64-_mapView.bounds.size.height;

return self;

self.tableView.frame=CGRectMake(0,CGRectGetMaxY(_mapView.frame),self.view.bounds.size.width, height);

}

}

//开首定点

/**

- startLocation

* 模拟数据

{

*/

[self.service startUserLocationService];

-(void)simulateData:(BMKUserLocation*)userLocation{

}

CGFloatlng =userLocation.location.coordinate.longitude;

//甘休定位

CGFloatlat = userLocation.location.coordinate.latitude;

- stopLocation

self.dataSoure= [bb电子糖果派对,NSMutableArrayarray];

{

for(inti =0; i <25; i++) {

上一篇:GCD的应用技艺
友情链接: 网站地图
Copyright © 2015-2019 http://www.tk-web.com. bb电子糖果派对有限公司 版权所有