From b1a650f3a6c52fa9dca9f9a9d1f982e27f6310de Mon Sep 17 00:00:00 2001 From: Adi Mor Barak Date: Sat, 21 Mar 2020 01:24:27 +0200 Subject: [PATCH] add CLFloor support - The floor of a building on which the user's device is located --- BackgroundGeolocation/MAURConfig.m | 1 + BackgroundGeolocation/MAURLocation.h | 1 + BackgroundGeolocation/MAURLocation.m | 11 ++++++-- BackgroundGeolocation/MAURLocationContract.h | 1 + BackgroundGeolocation/MAURLocationContract.m | 1 + BackgroundGeolocation/MAURSQLiteLocationDAO.m | 26 +++++++++++++------ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/BackgroundGeolocation/MAURConfig.m b/BackgroundGeolocation/MAURConfig.m index 63284e2..a26612d 100644 --- a/BackgroundGeolocation/MAURConfig.m +++ b/BackgroundGeolocation/MAURConfig.m @@ -406,6 +406,7 @@ + (NSDictionary*) getDefaultTemplate @"altitude": @"@altitude", @"latitude": @"@latitude", @"longitude": @"@longitude", + @"floor": @"@floor", @"provider": @"provider", @"locationProvider": @"@locationProvider", @"radius": @"@radius", diff --git a/BackgroundGeolocation/MAURLocation.h b/BackgroundGeolocation/MAURLocation.h index 88e33e0..703dc99 100644 --- a/BackgroundGeolocation/MAURLocation.h +++ b/BackgroundGeolocation/MAURLocation.h @@ -31,6 +31,7 @@ typedef NS_ENUM(NSInteger, MAURLocationStatus) { @property (nonatomic, retain) NSNumber *heading; @property (nonatomic, retain) NSNumber *altitude; @property (nonatomic, retain) NSNumber *latitude; +@property (nonatomic, retain) NSNumber *floor; @property (nonatomic, retain) NSNumber *longitude; @property (nonatomic, retain) NSString *provider; @property (nonatomic, retain) NSNumber *locationProvider; diff --git a/BackgroundGeolocation/MAURLocation.m b/BackgroundGeolocation/MAURLocation.m index d6e35f9..d5a1a1b 100644 --- a/BackgroundGeolocation/MAURLocation.m +++ b/BackgroundGeolocation/MAURLocation.m @@ -70,7 +70,7 @@ + (instancetype) map:(MAURLocation*)location @implementation MAURLocation -@synthesize locationId, time, accuracy, altitudeAccuracy, speed, heading, altitude, latitude, longitude, provider, locationProvider, radius, isValid, recordedAt; +@synthesize locationId, time, accuracy, altitudeAccuracy, speed, heading, altitude, latitude, longitude, floor, provider, locationProvider, radius, isValid, recordedAt; + (instancetype) fromCLLocation:(CLLocation*)location; { @@ -84,6 +84,7 @@ + (instancetype) fromCLLocation:(CLLocation*)location; instance.altitude = [NSNumber numberWithDouble:location.altitude]; instance.latitude = [NSNumber numberWithDouble:location.coordinate.latitude]; instance.longitude = [NSNumber numberWithDouble:location.coordinate.longitude]; + instance.floor = [NSNumber numberWithDouble:location.floor.level]; return instance; } @@ -107,6 +108,7 @@ + (NSDictionary*) toDictionary:(CLLocation*)location; [dict setObject:[NSNumber numberWithDouble:location.altitude] forKey:@"altitude"]; [dict setObject:[NSNumber numberWithDouble:location.coordinate.latitude] forKey:@"latitude"]; [dict setObject:[NSNumber numberWithDouble:location.coordinate.longitude] forKey:@"longitude"]; + [dict setObject:[NSNumber numberWithDouble:location.floor.level] forKey:@"floor"]; return dict; } @@ -158,6 +160,7 @@ - (NSMutableDictionary*) toDictionary if (altitude != nil) [dict setObject:altitude forKey:@"altitude"]; if (latitude != nil) [dict setObject:latitude forKey:@"latitude"]; if (longitude != nil) [dict setObject:longitude forKey:@"longitude"]; + if (floor != nil) [dict setObject:floor forKey:@"floor"]; if (provider != nil) [dict setObject:provider forKey:@"provider"]; if (locationProvider != nil) [dict setObject:locationProvider forKey:@"locationProvider"]; if (radius != nil) [dict setObject:radius forKey:@"radius"]; @@ -202,6 +205,9 @@ - (id) getValueForKey:(id)key if ([key isEqualToString:@"@longitude"]) { return longitude; } + if ([key isEqualToString:@"@floor"]) { + return floor; + } if ([key isEqualToString:@"@provider"]) { return provider; } @@ -322,7 +328,7 @@ - (BOOL) hasTime - (NSString *) description { - return [NSString stringWithFormat:@"Location: id=%@ time=%@ lat=%@ lon=%@ accu=%@ aaccu=%@ speed=%@ bear=%@ alt=%@", locationId, time, latitude, longitude, accuracy, altitudeAccuracy, speed, heading, altitude]; + return [NSString stringWithFormat:@"Location: id=%@ time=%@ lat=%@ lon=%@ floor=%@ accu=%@ aaccu=%@ speed=%@ bear=%@ alt=%@", locationId, time, latitude, longitude, floor, accuracy, altitudeAccuracy, speed, heading, altitude]; } -(id) copyWithZone: (NSZone *) zone @@ -337,6 +343,7 @@ -(id) copyWithZone: (NSZone *) zone copy.altitude = altitude; copy.latitude = latitude; copy.longitude = longitude; + copy.floor = floor; copy.provider = provider; copy.locationProvider = locationProvider; copy.radius = radius; diff --git a/BackgroundGeolocation/MAURLocationContract.h b/BackgroundGeolocation/MAURLocationContract.h index cd595a5..fb92187 100644 --- a/BackgroundGeolocation/MAURLocationContract.h +++ b/BackgroundGeolocation/MAURLocationContract.h @@ -19,6 +19,7 @@ #define LC_COLUMN_NAME_ALTITUDE "altitude" #define LC_COLUMN_NAME_LATITUDE "latitude" #define LC_COLUMN_NAME_LONGITUDE "longitude" +#define LC_COLUMN_NAME_FLOOR "floor" #define LC_COLUMN_NAME_PROVIDER "provider" #define LC_COLUMN_NAME_LOCATION_PROVIDER "service_provider" #define LC_COLUMN_NAME_STATUS "valid" diff --git a/BackgroundGeolocation/MAURLocationContract.m b/BackgroundGeolocation/MAURLocationContract.m index 31108e7..6d65198 100644 --- a/BackgroundGeolocation/MAURLocationContract.m +++ b/BackgroundGeolocation/MAURLocationContract.m @@ -23,6 +23,7 @@ + (NSString*) createTableSQL @{ @"name": @LC_COLUMN_NAME_ALTITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]}, @{ @"name": @LC_COLUMN_NAME_LATITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]}, @{ @"name": @LC_COLUMN_NAME_LONGITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]}, + @{ @"name": @LC_COLUMN_NAME_FLOOR, @"type": [SQLColumnType sqlColumnWithType: kReal]}, @{ @"name": @LC_COLUMN_NAME_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]}, @{ @"name": @LC_COLUMN_NAME_LOCATION_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]}, @{ @"name": @LC_COLUMN_NAME_STATUS, @"type": [SQLColumnType sqlColumnWithType: kInteger]}, diff --git a/BackgroundGeolocation/MAURSQLiteLocationDAO.m b/BackgroundGeolocation/MAURSQLiteLocationDAO.m index d675fa3..1312413 100644 --- a/BackgroundGeolocation/MAURSQLiteLocationDAO.m +++ b/BackgroundGeolocation/MAURSQLiteLocationDAO.m @@ -51,6 +51,7 @@ - (id) init { @COMMA_SEP @LC_COLUMN_NAME_ALTITUDE @COMMA_SEP @LC_COLUMN_NAME_LATITUDE @COMMA_SEP @LC_COLUMN_NAME_LONGITUDE + @COMMA_SEP @LC_COLUMN_NAME_FLOOR @COMMA_SEP @LC_COLUMN_NAME_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_LOCATION_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_RECORDED_AT @@ -69,8 +70,9 @@ - (id) init { location.altitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:5]]; location.latitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:6]]; location.longitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:7]]; - location.provider = [rs stringForColumnIndex:8]; - location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:9]]; + location.floor = [NSNumber numberWithDouble:[rs doubleForColumnIndex:8]]; + location.provider = [rs stringForColumnIndex:9]; + location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:10]]; NSTimeInterval recordedAt = [rs longForColumnIndex:11]; location.recordedAt = [NSDate dateWithTimeIntervalSince1970:recordedAt]; @@ -98,6 +100,7 @@ - (id) init { @COMMA_SEP @LC_COLUMN_NAME_ALTITUDE @COMMA_SEP @LC_COLUMN_NAME_LATITUDE @COMMA_SEP @LC_COLUMN_NAME_LONGITUDE + @COMMA_SEP @LC_COLUMN_NAME_FLOOR @COMMA_SEP @LC_COLUMN_NAME_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_LOCATION_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_STATUS @@ -117,10 +120,11 @@ - (id) init { location.altitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:5]]; location.latitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:6]]; location.longitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:7]]; - location.provider = [rs stringForColumnIndex:8]; - location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:9]]; - location.isValid = [rs intForColumnIndex:10] == 1 ? YES : NO; - NSTimeInterval recordedAt = [rs longForColumnIndex:11]; + location.floor = [NSNumber numberWithDouble:[rs doubleForColumnIndex:8]]; + location.provider = [rs stringForColumnIndex:9]; + location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:10]]; + location.isValid = [rs intForColumnIndex:11] == 1 ? YES : NO; + NSTimeInterval recordedAt = [rs longForColumnIndex:12]; location.recordedAt = [NSDate dateWithTimeIntervalSince1970:recordedAt]; [locations addObject:location]; @@ -148,6 +152,7 @@ - (id) init { @COMMA_SEP @LC_COLUMN_NAME_ALTITUDE @COMMA_SEP @LC_COLUMN_NAME_LATITUDE @COMMA_SEP @LC_COLUMN_NAME_LONGITUDE + @COMMA_SEP @LC_COLUMN_NAME_FLOOR @COMMA_SEP @LC_COLUMN_NAME_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_LOCATION_PROVIDER @" FROM " @LC_TABLE_NAME @" WHERE " @LC_COLUMN_NAME_STATUS @" = ? ORDER BY " @LC_COLUMN_NAME_RECORDED_AT; @@ -164,8 +169,9 @@ - (id) init { location.altitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:5]]; location.latitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:6]]; location.longitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:7]]; - location.provider = [rs stringForColumnIndex:8]; - location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:9]]; + location.floor = [NSNumber numberWithDouble:[rs doubleForColumnIndex:8]]; + location.provider = [rs stringForColumnIndex:9]; + location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:10]]; [locations addObject:location]; } @@ -212,6 +218,7 @@ - (NSNumber*) persistLocation:(MAURLocation*)location intoDatabase:(FMDatabase*) @COMMA_SEP @LC_COLUMN_NAME_ALTITUDE @COMMA_SEP @LC_COLUMN_NAME_LATITUDE @COMMA_SEP @LC_COLUMN_NAME_LONGITUDE + @COMMA_SEP @LC_COLUMN_NAME_FLOOR @COMMA_SEP @LC_COLUMN_NAME_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_LOCATION_PROVIDER @COMMA_SEP @LC_COLUMN_NAME_STATUS @@ -226,6 +233,7 @@ - (NSNumber*) persistLocation:(MAURLocation*)location intoDatabase:(FMDatabase*) location.altitude, location.latitude, location.longitude, + location.floor, location.provider ?: [NSNull null], location.locationProvider ?: [NSNull null], location.isValid == YES ? @(1) : @(0), @@ -296,6 +304,7 @@ - (NSNumber*) persistLocation:(MAURLocation*)location limitRows:(NSInteger)maxRo @COMMA_SEP @LC_COLUMN_NAME_ALTITUDE @EQ_BIND @COMMA_SEP @LC_COLUMN_NAME_LATITUDE @EQ_BIND @COMMA_SEP @LC_COLUMN_NAME_LONGITUDE @EQ_BIND + @COMMA_SEP @LC_COLUMN_NAME_FLOOR @EQ_BIND @COMMA_SEP @LC_COLUMN_NAME_PROVIDER @EQ_BIND @COMMA_SEP @LC_COLUMN_NAME_LOCATION_PROVIDER @EQ_BIND @COMMA_SEP @LC_COLUMN_NAME_STATUS @EQ_BIND @@ -310,6 +319,7 @@ - (NSNumber*) persistLocation:(MAURLocation*)location limitRows:(NSInteger)maxRo location.altitude, location.latitude, location.longitude, + location.floor, location.provider ?: [NSNull null], location.locationProvider ?: [NSNull null], location.isValid == YES ? @(1) : @(0),