diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-10-03 11:33:38 +0200 |
---|---|---|
committer | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2016-12-22 13:58:45 +0100 |
commit | 2c7569b879eb2bc9438a17226b333392052dd2db (patch) | |
tree | 1e62ab55e23c7a7be057b437f8b6aecfd21d764a /platform/darwin/src/NSArray+MGLAdditions.mm | |
parent | 916cd6c310ee4b7978efa9010123673f067ca6a9 (diff) | |
download | qtlocation-mapboxgl-2c7569b879eb2bc9438a17226b333392052dd2db.tar.gz |
[ios, macos] features and annotations now conforms to NSSecureCoding
Diffstat (limited to 'platform/darwin/src/NSArray+MGLAdditions.mm')
-rw-r--r-- | platform/darwin/src/NSArray+MGLAdditions.mm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/platform/darwin/src/NSArray+MGLAdditions.mm b/platform/darwin/src/NSArray+MGLAdditions.mm index b2799c46e1..f2c5a096cc 100644 --- a/platform/darwin/src/NSArray+MGLAdditions.mm +++ b/platform/darwin/src/NSArray+MGLAdditions.mm @@ -38,4 +38,28 @@ return attributedString; } ++ (NSArray *)mgl_coordinatesFromCoordinates:(std::vector<CLLocationCoordinate2D>)coords { + NSMutableArray *coordinates = [NSMutableArray array]; + for (auto coord : coords) { + [coordinates addObject:@{@"latitude": @(coord.latitude), + @"longitude": @(coord.longitude)}]; + } + return coordinates; +} + +- (std::vector<CLLocationCoordinate2D>)mgl_coordinates { + NSUInteger numberOfCoordinates = [self count]; + CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(numberOfCoordinates * sizeof(CLLocationCoordinate2D)); + + for (NSUInteger i = 0; i < numberOfCoordinates; i++) { + coords[i] = CLLocationCoordinate2DMake([self[i][@"latitude"] doubleValue], + [self[i][@"longitude"] doubleValue]); + } + + std::vector<CLLocationCoordinate2D> coordinates = { coords, coords + numberOfCoordinates }; + free(coords); + + return coordinates; +} + @end |