Advertisement
wkerswell

mapView

Oct 23rd, 2012
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  MapViewController.m
  3. //  CPOP Test 4
  4. //
  5. //  Created by Will Kerswell on 03/10/2012.
  6. //  Copyright (c) 2012 Will Kerswell. All rights reserved.
  7. //
  8.  
  9. #import "MapViewController.h"
  10. #import "UIDevice+Resolutions.h"
  11. #import "DataBase.h"
  12. #import "MapViewController.h"
  13.  
  14. @implementation MapViewController
  15. @synthesize showMapView;
  16. @synthesize mapSgementedControl;
  17.  
  18.  
  19.  
  20. /////////////////////////////
  21. #pragma mark - Pin Display
  22. /////////////////////////////
  23.  
  24.  
  25. -(void)pins
  26. {
  27.     //Set coordinates of pin
  28.     CLLocationCoordinate2D coordinate;
  29.     coordinate.latitude = 51.484864;
  30.     coordinate.longitude = -2.76013;
  31.    
  32.     //Create Pin
  33.     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
  34.     [annotation setCoordinate:coordinate];
  35.     [annotation setTitle:@"The Office"];
  36.     [annotation setSubtitle:@"Here is where we do all our work!"];
  37.    
  38.     // Add pin to map
  39.     [self.showMapView addAnnotation:annotation];
  40.    
  41.     //This will allow you to open up safari when the button is pressed:
  42.     //[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"URL goes here"]];
  43. }
  44.  
  45. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
  46.     MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
  47.     if (!pinView) {
  48.         pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
  49.         pinView.pinColor = MKPinAnnotationColorRed;
  50.         pinView.animatesDrop = YES;
  51.         pinView.canShowCallout = YES;
  52.        
  53.         UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  54.         pinView.rightCalloutAccessoryView = rightButton;
  55.     } else {
  56.         pinView.annotation = annotation;
  57.     }
  58.     return pinView;
  59. }
  60.  
  61.  
  62. //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
  63. - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
  64.     NSLog(@"Pin button pressed");
  65.     //myLabel.text=@"hi";
  66. }
  67.  
  68.  
  69. /////////////////////////////
  70. #pragma mark - Map Didplay
  71. /////////////////////////////
  72.  
  73. - (IBAction)mapSize:(id)sender {
  74.     //Chane between local and wide view.
  75.     switch (self.mapSgementedControl.selectedSegmentIndex) {
  76.         case 0:
  77.            
  78.             NSLog(@"Wide");
  79.             [self wideMap];
  80.             break;
  81.         case 1:
  82.            
  83.            
  84.             NSLog(@"Local");
  85.             [self localMap];
  86.         default:
  87.             break;
  88.     }
  89. }
  90.  
  91. -(void)wideMap{
  92.     //zooms the map out so the user can see the surrondings
  93.     showMapView.mapType= MKMapTypeStandard;
  94.     MKCoordinateRegion newRegion;
  95.     newRegion.center.latitude = LAT_POSN ;
  96.     newRegion.center.longitude = LON_POSN;
  97.     newRegion.span.latitudeDelta = 0.181168;
  98.     newRegion.span.longitudeDelta = 0.43911;
  99.     [self.showMapView setRegion:newRegion animated:YES];
  100.    
  101. }
  102. -(void) localMap{
  103.     //zooms the user into the local view so they can see the ground.
  104. //    [self.coord addObject:@"53.057801"];
  105. //    [self.coord addObject:@"-2.68779504298"];
  106. //    [self.coord addObject:@"0.011323"];
  107. //    [self.coord addObject:@"53.057801"];
  108.    
  109.     showMapView.mapType= MKMapTypeStandard;
  110.     MKCoordinateRegion newRegion;
  111.     newRegion.center.latitude = 53.057801 ;
  112.     newRegion.center.longitude = -2.68779504298;
  113.     newRegion.span.latitudeDelta = 0.011323;
  114.     newRegion.span.longitudeDelta = 0.027444;
  115.         NSLog(@"%f",newRegion.center.latitude);
  116.         NSLog(@"%f",newRegion.center.longitude);
  117.         NSLog(@"%f",newRegion.span.latitudeDelta);
  118.         NSLog(@"%f",newRegion.span.longitudeDelta);
  119.     [self.showMapView setRegion:newRegion animated:YES];
  120.    
  121.  
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. /////////////////////////////
  131. #pragma mark - View Licfcycle
  132. /////////////////////////////
  133.  
  134. - (void)viewDidLoad
  135. {
  136.     //makes the top title black in the more or the tabbar view
  137.     self.tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
  138.    
  139.     //Test to see if the user is using an iPhone 5
  140.     //This can be to change things depending on the screen size.
  141.     if ([UIDevice deviceType] & iPhone5){
  142.         NSLog(@"iPhone 5");
  143.     }
  144.    
  145.     NSLog(@"This has run");
  146.    
  147.     //start map
  148.     [self localMap];
  149.    
  150.     [super viewDidLoad];
  151. }
  152.  
  153.  
  154.  
  155.  
  156. //other lifecycle methods.
  157.  
  158.  
  159. - (void)didReceiveMemoryWarning
  160. {
  161.     [super didReceiveMemoryWarning];
  162.     // Dispose of any resources that can be recreated.
  163. }
  164.  
  165. - (void)viewDidUnload {
  166.  
  167.     [super viewDidUnload];
  168. }
  169.  
  170. - (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
  171.     UIView *editView = [controller.view.subviews objectAtIndex:1];
  172.     UINavigationBar *modalNavBar = [editView.subviews objectAtIndex:0];
  173.     modalNavBar.tintColor = [UIColor blackColor];
  174. }
  175.  
  176.  
  177. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement