- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [rfduino setDelegate:self]; UIColor *start = [UIColor colorWithRed:58/255.0 green:108/255.0 blue:183/255.0 alpha:0.15]; UIColor *stop = [UIColor colorWithRed:58/255.0 green:108/255.0 blue:183/255.0 alpha:0.45]; CAGradientLayer *gradient = [CAGradientLayer layer]; //gradient.frame = [self.view bounds]; gradient.frame = CGRectMake(0.0, 0.0, 1024.0, 1024.0); gradient.colors = [NSArray arrayWithObjects:(id)start.CGColor, (id)stop.CGColor, nil]; [self.view.layer insertSublayer:gradient atIndex:0]; off = [UIImage imageNamed:@"off.jpg"]; on = [UIImage imageNamed:@"on.jpg"]; //MAP VIEW CODE [mapView setMapType:MKMapTypeStandard]; [mapView setZoomEnabled:YES]; [mapView setScrollEnabled:YES]; [mapView setShowsUserLocation:YES]; //GETTING CURRENT LOCATION locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy=kCLLocationAccuracyBest; [locationManager requestAlwaysAuthorization]; locationManager.distanceFilter = 100.0f; [locationManager startUpdatingLocation]; //TEST DATA CLLocationDegrees latitude_test = 32; CLLocationDegrees longitude_test = 33; //call 1 "right" and 2 "left" NSInteger *test_direction = 1; //ATTEMPT AT GETTING DIRECTIONS FROM MKMAPS /********************************************/ CLLocationCoordinate2D destinationCoords = CLLocationCoordinate2DMake(42.365701, -71.1); MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:destinationCoords addressDictionary:nil]; MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark]; MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init]; [request setSource:[MKMapItem mapItemForCurrentLocation]]; [request setDestination: destination]; [request setTransportType:MKDirectionsTransportTypeWalking]; [request setRequestsAlternateRoutes:NO]; MKDirections *directions = [[MKDirections alloc] initWithRequest:request]; [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) { if(!error) { MKRoute *route = response.routes[0]; for( MKRouteStep *step in [route steps]) { CLLocationDegrees currentLongitude = currentLocation.coordinate.longitude; CLLocationDegrees currentLatitude = currentLocation.coordinate.latitude; for(int x=0; x<4; x++) if(latitude_test==currentLatitude && longitude_test==currentLongitude) { [self sendByte:test_direction]; } NSLog(@"current latitude: %f", currentLatitude); sleep(1); MKMapPoint next = MKMapPointForCoordinate(CLLocationCoordinate2DMake(currentLatitude, currentLongitude)); if(step.polyline.points[0].x == next.x && step.polyline.points[0].y == next.y) { NSLog(@"Description: %@", [step description]); if([step.description containsString:@"left"]) { NSLog(@"left"); [self sendByte:1]; } else if([step.description containsString:@"right"]) { NSLog(@"right"); [self sendByte:2]; } else [self sendByte:0]; } } } }]; /********************************************/ }