Created
March 24, 2012 03:58
-
-
Save avleen/2178025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MapViewAnnotation.h | |
#import <Foundation/Foundation.h> | |
#import <MapKit/MapKit.h> | |
@interface MapViewAnnotation : NSObject <MKAnnotation> { | |
NSString *title; | |
CLLocationCoordinate2D coordinate; | |
} | |
@property (nonatomic, copy) NSString *title; | |
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; | |
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d; | |
@end | |
// MapViewAnnotation.m | |
#import "MapViewAnnotation.h" | |
@implementation MapViewAnnotation | |
@synthesize title, coordinate; | |
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d { | |
title = ttl; | |
coordinate = c2d; | |
return self; | |
} | |
@end | |
// ViewController.m | |
- (void)drawMarkers { | |
NSURL *markers_url = [NSURL URLWithString:@"http://url"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:markers_url]; | |
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; | |
NSError *jsonParsingError = nil; | |
NSDictionary *markers = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError]; | |
for (NSDictionary *marker in markers) { | |
CLLocationCoordinate2D tornadoLocation; | |
NSString *latitude = [marker objectForKey:@"lat"]; | |
NSString *longitude = [marker objectForKey:@"lng"]; | |
NSLog(@"Downloaded lat, lng: %@, %@", latitude, longitude); | |
tornadoLocation.latitude = [latitude doubleValue]; | |
tornadoLocation.longitude = [longitude doubleValue]; | |
MapViewAnnotation *annotation = [[MapViewAnnotation alloc] initWithTitle:@"Mark" andCoordinate:tornadoLocation]; | |
[mapView addAnnotation:annotation]; | |
} | |
} | |
// EXAMPLE LOG: | |
2012-03-23 22:53:53.109 MyApp[13252:11603] Downloaded lat, lng: 39.028171999999998, -84.724039000000005 | |
2012-03-23 22:53:53.109 MyApp[13252:11603] Downloaded lat, lng: 39.825825000000002, -86.238016999999999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment