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

1.//开启后台定位

self.service.allowsBackgroundLocationUpdates = YES;

2.

本地图片,请重新上传

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

本地图片,请重新上传

//在此处创建的单例类,整个工程都可以使用,开启和定位

#import "LocationManager.h"

#import "SQLManager.h"

#import "ZYPoint.h"

#define UPLOAD_TRACEURL @"http://www.16d1.com/index.php/home/api/logtrace.html"

@implementation LocationManager

static LocationManager *manager = nil;

static BMKMapView *mapView = nil;

static NSMutableDictionary*tempDic = nil;

static NSMutableArray*_togetherArr = nil;

static NSMutableDictionary*dic = nil;

//创建单例类

+(LocationManager *)manager

{

if (!manager)

{

manager = [[LocationManager alloc] init];

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

_togetherArr=[[NSMutableArray alloc]init];

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

}

return manager;

}

- (id)init

{

self = [super init];

if (self)

{

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

self.service.distanceFilter = 10;

self.service.delegate = self;

//开启后台定位

self.service.allowsBackgroundLocationUpdates = YES;

//开启定位

[self.service startUserLocationService];

}

return self;

}

//开始定位

- (void)startLocation

{

[self.service startUserLocationService];

}

//停止定位

- (void)stopLocation

{

[self.service stopUserLocationService];

}

#pragma mark - BMKLocationServiceDelegate

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

self.userLocation1 = userLocation;

mapView.showsUserLocation=YES;

NSLog(@"%f  %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);

[[NSNotificationCenter defaultCenter] postNotificationName:@"map" object:nil userInfo:nil];

/**

*  存储数据库

*/

if ([self isLogin])

{

#warning REMEMBER 在以后将该过程放在分线程中进行

//判断是否上传数据

NSString*currentTime=[self getCurrentTime];

NSMutableArray*tempArray=[SQLManager getArrayFromSelectData];

for (int a=0; a

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容