Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.
/ GeoJSONSerialization Public archive

Encode & Decode Between GeoJSON & MapKit Shapes

License

Notifications You must be signed in to change notification settings

mattt/GeoJSONSerialization

Repository files navigation

GeoJSONSerialization

This library is no longer maintained. In iOS 13+ and macOS 10.15+, use MKGeoJSONDecoder instead.

GeoJSONSerialization encodes and decodes between GeoJSON and MapKit shapes, following the API conventions of Foundation's NSJSONSerialization class.

Usage

Decoding

#import <MapKit/MapKit.h>
#import "GeoJSONSerialization.h"

NSURL *URL = [[NSBundle mainBundle] URLForResource:@"map" withExtension:@"geojson"];
NSData *data = [NSData dataWithContentsOfURL:URL];
NSDictionary *geoJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSArray *shapes = [GeoJSONSerialization shapesFromGeoJSONFeatureCollection:geoJSON error:nil];

for (MKShape *shape in shapes) {
    if ([shape isKindOfClass:[MKPointAnnotation class]]) {
        [mapView addAnnotation:shape];
    } else if ([shape conformsToProtocol:@protocol(MKOverlay)]) {
        [mapView addOverlay:(id <MKOverlay>)shape];
    }
}

After implementing the necessary MKMapViewDelegate methods, the resulting map will look something like this.

Contact

Mattt

License

GeoJSONSerialization is available under the MIT license. See the LICENSE file for more info.

About

Encode & Decode Between GeoJSON & MapKit Shapes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •