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