Skip to content

Instantly share code, notes, and snippets.

@ziyang0621
Created August 7, 2015 21:38
Show Gist options
  • Save ziyang0621/4e572ef551293febd9ae to your computer and use it in GitHub Desktop.
Save ziyang0621/4e572ef551293febd9ae to your computer and use it in GitHub Desktop.
#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