Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////
- #pragma mark - Pin Display
- /////////////////////////////
- -(void)pins:(NSString *)name lat:(NSString *)lat lon:(NSString *)lon poiID:(NSString *)poiID
- {
- //cast string to float
- CGFloat Lat = (CGFloat)[lat floatValue];
- CGFloat Lon = (CGFloat)[lon floatValue];
- //Set coordinates of pin
- CLLocationCoordinate2D coordinate;
- coordinate.latitude = Lat;
- coordinate.longitude = Lon;
- //Create Pin
- MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
- //set details
- [annotation setCoordinate:coordinate];
- [annotation setTitle:name];
- [annotation setAccessibilityLabel:poiID]; //set the label eq to the id so we know which poi page to go to
- // Add pin to map
- [self.showMapView addAnnotation:annotation];
- }
- - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
- //create annotation
- MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
- if (!pinView) {
- pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
- pinView.pinColor = MKPinAnnotationColorRed;
- pinView.animatesDrop = FALSE;
- pinView.canShowCallout = YES;
- //details button
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
- pinView.rightCalloutAccessoryView = rightButton;
- } else {
- pinView.annotation = annotation;
- }
- return pinView;
- }
- //IMPLEMENT THIS ONE (WHEN DISCLOSURE BUTTON IS PRESSED):
- - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
- //create and annotation
- MKPointAnnotation *annotation = view.annotation;
- //set global var eq to the id
- self.POIID = annotation.accessibilityLabel;
- //NSLog(@"Pin button pressed: %@",temp);
- [self performSegueWithIdentifier:@"showDetail" sender:self];
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if ([[segue identifier] isEqualToString:@"showDetail"]) {
- //say where its going
- DetailsViewController *detailViewController = [segue destinationViewController];
- //set the poiID in the next view eq to the row pressed.
- detailViewController.poiID = self.POIID;
- }
- if ([[segue identifier] isEqualToString:@"showAlternate"]) {
- [[segue destinationViewController] setDelegate:self];
- }
- }
- /////////////////////////////
- #pragma mark - Map Didplay
- /////////////////////////////
- - (IBAction)mapSize:(id)sender {
- //Chane between local and wide view.
- switch (self.mapSgementedControl.selectedSegmentIndex) {
- case 0:
- NSLog(@"Wide");
- [self wideMap];
- break;
- case 1:
- NSLog(@"Local");
- [self localMap];
- default:
- break;
- }
- }
- -(void)wideMap{
- //zooms the map out so the user can see the surrondings
- showMapView.mapType= MKMapTypeStandard;
- MKCoordinateRegion newRegion;
- newRegion.center.latitude = LAT_POSN ;
- newRegion.center.longitude = LON_POSN;
- newRegion.span.latitudeDelta = 0.181168;
- newRegion.span.longitudeDelta = 0.43911;
- [self.showMapView setRegion:newRegion animated:YES];
- }
- -(void) localMap{
- //zooms the user into the local view so they can see the ground.
- showMapView.mapType= MKMapTypeStandard;
- MKCoordinateRegion newRegion;
- newRegion.center.latitude = LAT_POSN ;
- newRegion.center.longitude = LON_POSN;
- newRegion.span.latitudeDelta = 0.002053;
- newRegion.span.longitudeDelta = 0.005747;
- //old span
- //newRegion.span.latitudeDelta = 0.011323;
- //newRegion.span.longitudeDelta = 0.027444;
- [self.showMapView setRegion:newRegion animated:NO];
- }
- -(void)addPins{
- //create an instance of the database oject
- DataBase * dataBase = [[DataBase alloc] init];
- //open the database connection
- [dataBase openDB];
- //get the user defualts
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- // getting an NSString
- NSDictionary *catToggle = [prefs dictionaryForKey:@"pinFilters"];
- //loop of the catids and toggles from the user defaults
- for (NSString *keys in catToggle) {
- //get on or off
- NSString *toggle = [[NSString alloc]init];
- toggle = [catToggle objectForKey:keys];
- if (toggle == @"ON"){
- NSMutableDictionary *poisForOneCat = [[NSMutableDictionary alloc]init ];
- //if on get the id name lat and long for the pois in that cat
- poisForOneCat = [dataBase getPOIInfoForMap:keys];
- for(NSString *key in poisForOneCat) {
- //loop over the pois in that cat can put them on the map!
- NSMutableArray *arrayOfPinInformation = [poisForOneCat objectForKey:key];
- NSLog(@"arrayOfPinInformation: %@",arrayOfPinInformation);
- [self pins:key lat:arrayOfPinInformation[1] lon:arrayOfPinInformation[2] poiID:arrayOfPinInformation[0]];
- }
- }
- }
- }
- /////////////////////////////
- #pragma mark - View Licfcycle
- /////////////////////////////
- - (void)viewDidLoad
- {
- //makes the top title black in the more or the tabbar view
- self.tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
- //Test to see if the user is using an iPhone 5
- //This can be to change things depending on the screen size if ([UIDevice deviceType] & iPhone5){
- NSLog(@"iPhone 5");
- //initialise array
- self.daoDS = [[POIDataDAO alloc] init];
- //set array of ojects to loacl array
- // self.ds = self.daoDS.PopulateDataSource;
- //set map delegate
- showMapView.delegate = (id)self;
- [self addPins];
- //force the map to start on the main queue
- dispatch_async(dispatch_get_main_queue(), ^{[self localMap];});
- [super viewDidLoad];
- }
- //other lifecycle methods.
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewDidUnload {
- [super viewDidUnload];
- }
- - (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
- UIView *editView = [controller.view.subviews objectAtIndex:1];
- UINavigationBar *modalNavBar = [editView.subviews objectAtIndex:0];
- modalNavBar.tintColor = [UIColor blackColor];
- }
- #pragma mark - Flipside View
- - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement