Created
September 14, 2012 07:00
-
-
Save ChrisRisner/3720365 to your computer and use it in GitHub Desktop.
GeoDemo-ios2
This file contains hidden or 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
- (void)fetchedData:(NSData *)responseData { | |
NSError* error; | |
//Build a JSON object from the response Data | |
NSArray* json = [NSJSONSerialization | |
JSONObjectWithData:responseData //1 | |
options:kNilOptions | |
error:&error]; | |
//Go through each POI in the JSON data and pull out the important fields | |
for (NSDictionary *pointOfInterest in json) { | |
NSLog(@"POI:%@", pointOfInterest); | |
CLLocationCoordinate2D mapPoint = mapView.centerCoordinate; | |
NSString *latString = [pointOfInterest valueForKey:@"Latitude"]; | |
NSString *longString = [pointOfInterest valueForKey:@"Longitude"]; | |
NSString *description = [pointOfInterest valueForKey:@"Description"]; | |
NSString *url = [pointOfInterest valueForKey:@"Url"]; | |
mapPoint.latitude = [latString doubleValue]; | |
mapPoint.longitude = [longString doubleValue]; | |
//Add a new map annotation for each POI | |
MKPointAnnotation *anny = [[MKPointAnnotation alloc] init]; | |
anny.coordinate = mapPoint; | |
anny.title = description; | |
anny.subtitle = url; | |
[mapView addAnnotation:anny]; | |
} | |
} |
This file contains hidden or 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
- (void)getCurrentPointsOfInterest { | |
NSURL *requestUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@?latitude=%f&longitude=%f&radiusInMeters=1000",kGetPOIUrl, [currentLocation coordinate].latitude, [currentLocation coordinate].longitude]]; | |
//Get our POI | |
dispatch_async(kBgQueue, ^{ | |
NSData* data = [NSData dataWithContentsOfURL: | |
requestUrl]; | |
[self performSelectorOnMainThread:@selector(fetchedData:) | |
withObject:data waitUntilDone:YES]; | |
}); | |
} |
This file contains hidden or 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
- (IBAction)tapRefresh:(id)sender { | |
[self getCurrentPointsOfInterest]; | |
} | |
- (void)locationError:(NSError *)error { | |
labelLatitude.text = [error description]; | |
labelLongitude.text = nil; | |
} | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
[self getCurrentPointsOfInterest]; | |
} |
This file contains hidden or 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
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation | |
{ | |
if ([annotation isKindOfClass:[MKUserLocation class]]) | |
{ | |
return nil; | |
} | |
static NSString *AnnotationViewID = @"annotationViewID"; | |
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; | |
if (annotationView == nil) | |
{ | |
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; | |
} | |
annotationView.canShowCallout = YES; | |
annotationView.annotation = annotation; | |
return annotationView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment