Skip to content

Instantly share code, notes, and snippets.

@Shahn-Auronas
Created June 16, 2014 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shahn-Auronas/dba8b8e009bfb209423c to your computer and use it in GitHub Desktop.
Save Shahn-Auronas/dba8b8e009bfb209423c to your computer and use it in GitHub Desktop.
Using button within project details page to display on map
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[tableView cellForRowAtIndexPath:indexPath] setSelected:YES];
if (indexPath.section == MAP_SECTION) {
if ([self.locationTextField isFirstResponder]) {
[self.locationTextField resignFirstResponder];
}
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:self.locationTextField.text
completionHandler:^(NSArray *placemarks, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"Geocode failed with error: %@", error);
[self displayError:error];
return;
} else if ([placemarks count] > 0){
CLPlacemark *compPM = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:compPM];
SXAComp *compLocal = [[SXAComp alloc] init];
compLocal = (SXAComp *)placemark.location;
MKCoordinateRegion region = self.mapView.region;
region.center = [(CLCircularRegion *)placemark.region center];
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;
[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:placemark];
[self.mapView selectAnnotation:placemark animated:YES];
NSLog(@"Receieved placemarks: %@", placemarks);
}
});
}
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment