I'm a amateur programer that just recently started trying out xcode. I was googling around trying to find an answer to my current problem in my App. (Which I'll get to in a bit.) And I found a excellent answer here at Stackoverflow.com, though I'm not sure how to implement it to my own coding. (link: Opening native google maps in Xcode )
Edited: Basically: I'm using a tabbar application where in one tab there is a mapview, which you can see according to the coding I have such things as hybrid, satellite etc, and a annotion pin to an coordinate that shows a location, which when you click on it you can see a button. And it is from here that I don't know what to do, since I want the button to link you to your "maps" app on your iphone, giving you the directions to the location from your current location. This question was asked in the link that I wrote. It received a answer, though I do not know how to implement this to my own coding.
Here's my own code:
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface SecondViewController : UIViewController{
MKMapView *mapview;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapview;
-(IBAction)setMap:(id)sender;
-(IBAction)getlocation;
@end
ViewController.m
#import "SecondViewController.h"
#import "Annotation.h"
@implementation SecondViewController
@synthesize mapview;
-(IBAction)getlocation {
mapview.showsUserLocation = YES;
}
-(IBAction)setMap:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType = MKMapTypeStandard;
break;
case 1:
mapview.mapType = MKMapTypeSatellite;
break;
case 2:
mapview.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
-(void)viewDidLoad {
[super viewDidLoad];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
[mapview setDelegate:self];
MKCoordinateRegion bigBen = { {0.0, 0.0} , {0.0, 0.0} };
bigBen.center.latitude = 38.849977;
bigBen.center.longitude = -122.519531;
bigBen.span.longitudeDelta = 0.02f;
bigBen.span.latitudeDelta = 0.02f;
[mapview setRegion:bigBen animated:YES];
Annotation *ann1 = [[Annotation alloc] init];
ann1.title = @"Name";
ann1.subtitle = @"Street";
ann1.coordinate = bigBen.center;
[mapview addAnnotation: ann1];
}
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([[annotation title] isEqualToString:@"The Place"]) {
[advertButton addTarget:self action:@selector(BigBenClicked:) forControlEvents:UIControlEventTouchUpInside];
}
MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
-(void)button:(id)sender {
NSLog(@"Button action");
}
@end
Cheers!