Advertisement
Guest User

MAp pins

a guest
Oct 30th, 2012
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////
  2. #pragma mark - Pin Display
  3. /////////////////////////////
  4.  
  5.  
  6. -(void)pins:(NSString *)name lat:(NSString *)lat lon:(NSString *)lon poiID:(NSString *)poiID
  7. {
  8.    
  9.     //cast string to float
  10.     CGFloat Lat = (CGFloat)[lat floatValue];
  11.     CGFloat Lon = (CGFloat)[lon floatValue];
  12.    
  13.     //Set coordinates of pin
  14.     CLLocationCoordinate2D coordinate;
  15.     coordinate.latitude = Lat;
  16.     coordinate.longitude = Lon;
  17.    
  18.     //Create Pin
  19.     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
  20.     //set details
  21.     [annotation setCoordinate:coordinate];
  22.     [annotation setTitle:name];
  23.     [annotation setAccessibilityLabel:poiID]; //set the label eq to the id so we know which poi page to go to
  24.    
  25.    
  26.     // Add pin to map
  27.     [self.showMapView addAnnotation:annotation];
  28. }
  29.  
  30. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
  31.     //create annotation
  32.     MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
  33.     if (!pinView) {
  34.         pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
  35.         pinView.pinColor = MKPinAnnotationColorRed;
  36.         pinView.animatesDrop = FALSE;
  37.         pinView.canShowCallout = YES;
  38.        
  39.         //details button
  40.         UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  41.         pinView.rightCalloutAccessoryView = rightButton;
  42.        
  43.     } else {
  44.         pinView.annotation = annotation;
  45.     }
  46.     return pinView;
  47. }
  48.  
  49.  
  50. //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
  51. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
  52.     //create and annotation
  53.     MKPointAnnotation *annotation = view.annotation;
  54.     //set global var eq to the id
  55.     self.POIID = annotation.accessibilityLabel;
  56.     //NSLog(@"Pin button pressed: %@",temp);
  57.     [self performSegueWithIdentifier:@"showDetail" sender:self];
  58.    
  59. }
  60.  
  61. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  62.    
  63.     if ([[segue identifier] isEqualToString:@"showDetail"]) {
  64.        
  65.         //say where its going
  66.         DetailsViewController *detailViewController = [segue destinationViewController];
  67.         //set the poiID in the next view eq to the row pressed.
  68.         detailViewController.poiID = self.POIID;
  69.        
  70.     }
  71.     if ([[segue identifier] isEqualToString:@"showAlternate"]) {
  72.         [[segue destinationViewController] setDelegate:self];
  73.     }
  74.  
  75.  
  76. }
  77.  
  78.  
  79. /////////////////////////////
  80. #pragma mark - Map Didplay
  81. /////////////////////////////
  82.  
  83. - (IBAction)mapSize:(id)sender {
  84.     //Chane between local and wide view.
  85.     switch (self.mapSgementedControl.selectedSegmentIndex) {
  86.         case 0:
  87.            
  88.             NSLog(@"Wide");
  89.             [self wideMap];
  90.             break;
  91.         case 1:
  92.            
  93.            
  94.             NSLog(@"Local");
  95.             [self localMap];
  96.         default:
  97.             break;
  98.     }
  99. }
  100.  
  101. -(void)wideMap{
  102.     //zooms the map out so the user can see the surrondings
  103.     showMapView.mapType= MKMapTypeStandard;
  104.     MKCoordinateRegion newRegion;
  105.     newRegion.center.latitude = LAT_POSN ;
  106.     newRegion.center.longitude = LON_POSN;
  107.     newRegion.span.latitudeDelta = 0.181168;
  108.     newRegion.span.longitudeDelta = 0.43911;
  109.     [self.showMapView setRegion:newRegion animated:YES];
  110.    
  111. }
  112.  
  113. -(void) localMap{
  114.     //zooms the user into the local view so they can see the ground.
  115.  
  116.     showMapView.mapType= MKMapTypeStandard;
  117.     MKCoordinateRegion newRegion;
  118.     newRegion.center.latitude = LAT_POSN ;
  119.     newRegion.center.longitude = LON_POSN;
  120.     newRegion.span.latitudeDelta = 0.002053;
  121.     newRegion.span.longitudeDelta = 0.005747;
  122.     //old span
  123.     //newRegion.span.latitudeDelta = 0.011323;
  124.     //newRegion.span.longitudeDelta = 0.027444;
  125.  
  126.     [self.showMapView setRegion:newRegion animated:NO];
  127.    
  128. }
  129.  
  130. -(void)addPins{
  131.     //create an instance of the database oject
  132.     DataBase * dataBase = [[DataBase alloc] init];
  133.     //open the database connection
  134.     [dataBase openDB];
  135.     //get the user defualts
  136.     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  137.     // getting an NSString
  138.     NSDictionary *catToggle = [prefs dictionaryForKey:@"pinFilters"];
  139.    
  140.     //loop of the catids and toggles from the user defaults
  141.     for (NSString *keys in catToggle) {
  142.        
  143.             //get on or off
  144.             NSString *toggle = [[NSString alloc]init];
  145.             toggle = [catToggle objectForKey:keys];
  146.            
  147.            
  148.             if (toggle == @"ON"){
  149.                 NSMutableDictionary *poisForOneCat = [[NSMutableDictionary alloc]init ];
  150.                 //if on get the id name lat and long for the pois in that cat
  151.                 poisForOneCat = [dataBase getPOIInfoForMap:keys];
  152.            
  153.                
  154.                 for(NSString *key in poisForOneCat) {
  155.                     //loop over the pois in that cat can put them on the map!
  156.                     NSMutableArray *arrayOfPinInformation = [poisForOneCat objectForKey:key];
  157.                     NSLog(@"arrayOfPinInformation: %@",arrayOfPinInformation);
  158.                    
  159.                     [self pins:key lat:arrayOfPinInformation[1] lon:arrayOfPinInformation[2] poiID:arrayOfPinInformation[0]];
  160.                
  161.             }
  162.         }
  163.     }
  164.    
  165.  
  166.    
  167. }
  168.  
  169. /////////////////////////////
  170. #pragma mark - View Licfcycle
  171. /////////////////////////////
  172.  
  173. - (void)viewDidLoad
  174. {
  175.     //makes the top title black in the more or the tabbar view
  176.     self.tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
  177.    
  178.     //Test to see if the user is using an iPhone 5
  179.     //This can be to change things depending on the screen size    if ([UIDevice deviceType] & iPhone5){
  180.     NSLog(@"iPhone 5");
  181.  
  182.  
  183.  
  184. //initialise array
  185. self.daoDS = [[POIDataDAO alloc] init];
  186. //set array of ojects to loacl array
  187. //  self.ds = self.daoDS.PopulateDataSource;
  188.  
  189. //set map delegate
  190. showMapView.delegate = (id)self;
  191.  
  192. [self addPins];
  193.  
  194.  
  195.  
  196. //force the map to start on the main queue
  197. dispatch_async(dispatch_get_main_queue(), ^{[self localMap];});
  198.  
  199. [super viewDidLoad];
  200. }
  201.  
  202.  
  203. //other lifecycle methods.
  204.  
  205.  
  206. - (void)didReceiveMemoryWarning
  207. {
  208.     [super didReceiveMemoryWarning];
  209.     // Dispose of any resources that can be recreated.
  210. }
  211.  
  212. - (void)viewDidUnload {
  213.    
  214.     [super viewDidUnload];
  215. }
  216.  
  217. - (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
  218.     UIView *editView = [controller.view.subviews objectAtIndex:1];
  219.     UINavigationBar *modalNavBar = [editView.subviews objectAtIndex:0];
  220.     modalNavBar.tintColor = [UIColor blackColor];
  221. }
  222.  
  223. #pragma mark - Flipside View
  224.  
  225. - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
  226. {
  227.     [self dismissViewControllerAnimated:YES completion:nil];
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement