Created
August 7, 2015 21:38
-
-
Save ziyang0621/4e572ef551293febd9ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () <CLLocationManagerDelegate> | |
@end | |
@implementation ViewController{ | |
NSString *currentLongitude; | |
NSString *currentLatitude; | |
NSString *googleMapsURL; | |
CLLocationManager *locationManager_; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
locationManager_ = [[CLLocationManager alloc] init]; | |
locationManager_.delegate = self; | |
locationManager_.distanceFilter = kCLDistanceFilterNone; | |
locationManager_.desiredAccuracy = kCLLocationAccuracyBest; | |
[locationManager_ requestAlwaysAuthorization]; | |
[locationManager_ startUpdatingLocation]; | |
} | |
- (IBAction)composeMailButton:(id)sender { | |
NSString *bodyHeader = @"Here are you directions:"; | |
NSString *mailBody = [NSString stringWithFormat:@"%@\n%@", bodyHeader, googleMapsURL]; | |
MFMailComposeViewController *emailComposer = [[MFMailComposeViewController alloc] init]; | |
[emailComposer setSubject:@"Google Maps Directions"]; | |
[emailComposer setMessageBody:mailBody isHTML:NO]; | |
[emailComposer setToRecipients:@[@"castro.michael87@gmail.com"]]; | |
[emailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; | |
[self presentViewController:emailComposer animated:YES completion:nil]; | |
} | |
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { | |
CLLocation *newLocation = [locations lastObject]; | |
googleMapsURL = [[NSString alloc] initWithFormat:@"https://maps.google.com?saddr=Current+Location&daddr=%1.6f,%1.6f",newLocation.coordinate.latitude, newLocation.coordinate.longitude]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment