-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathCLPlacemarkExtensions.m
More file actions
61 lines (49 loc) · 2.14 KB
/
CLPlacemarkExtensions.m
File metadata and controls
61 lines (49 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// CLPlacemarkExtensions.m
// geocoding
//
// Created by Maurits van Beusekom on 07/06/2020.
//
#import <AddressBook/AddressBook.h>
#import <Contacts/Contacts.h>
#import "CLPlacemarkExtensions.h"
@implementation CLPlacemark (CLPlacemarkExtensions)
- (NSDictionary *)toPlacemarkDictionary {
NSString* street = @"";
if (self.postalAddress != nil) {
street = self.postalAddress.street;
}
NSMutableDictionary<NSString *, NSObject *> *dict = [[NSMutableDictionary alloc] initWithDictionary:@{
@"name": self.name == nil ? @"" : self.name,
@"street": street == nil ? @"" : street,
@"isoCountryCode": self.ISOcountryCode == nil ? @"" : self.ISOcountryCode,
@"country": self.country == nil ? @"" : self.country,
@"thoroughfare": self.thoroughfare == nil ? @"" : self.thoroughfare,
@"subThoroughfare": self.subThoroughfare == nil ? @"" : self.subThoroughfare,
@"postalCode": self.postalCode == nil ? @"" : self.postalCode,
@"administrativeArea": self.administrativeArea == nil ? @"" : self.administrativeArea,
@"subAdministrativeArea": self.subAdministrativeArea == nil ? @"" : self.subAdministrativeArea,
@"locality": self.locality == nil ? @"" : self.locality,
@"subLocality": self.subLocality == nil ? @"" : self.subLocality,
}];
return dict;
}
- (NSDictionary *)toLocationDictionary {
if (self.location == nil) {
return nil;
}
NSArray *lines = self.addressDictionary[@"FormattedAddressLines"];
NSMutableDictionary<NSString *, NSObject*> *dict = [[NSMutableDictionary alloc] initWithDictionary:@{
@"title": self.name,
@"description": [lines componentsJoinedByString:@", "] ?: [NSNull null],
@"latitude": @(self.location.coordinate.latitude),
@"longitude": @(self.location.coordinate.longitude),
@"timestamp": @([CLPlacemark currentTimeInMilliSeconds: self.location.timestamp]),
}];
return dict;
}
+ (double)currentTimeInMilliSeconds:(NSDate *)dateToConvert {
NSTimeInterval since1970 = [dateToConvert timeIntervalSince1970];
return since1970 * 1000;
}
@end