-4

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!

Community
  • 1
  • 1
  • 3
    And what is your question? – Till Dec 27 '12 at 23:00
  • How to implement the answer I found in the link to my own coding. – Jakob Håkansson Dec 27 '12 at 23:02
  • 1
    I think you'll have to be more specific - its not clear what you're asking here. – Krease Dec 27 '12 at 23:04
  • 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 a coordinate that shows a location, which when you click on it you can see a button. And is from here 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. – Jakob Håkansson Dec 27 '12 at 23:10

1 Answers1

0

You have already set a selector for when the button is pressed. Just implement the method and it should work.

-(void)BigBenClicked:(id)sender {
    NSURL *url = [self getURL];
    [[UIApplication sharedApplication] openURL:url];
}
Dale Myers
  • 2,703
  • 3
  • 26
  • 48
  • That's the things, I'm totally new to coding, so I'm not quiet sure where or what to implement! heh!.. – Jakob Håkansson Dec 27 '12 at 23:21
  • See my edit. Implement a method getURL which returns the URL that is generated in the other code. Simple as that. – Dale Myers Dec 27 '12 at 23:28
  • 1
    switch that with: " -(void)button:(id)sender " ? Cause then there's no visible @interface that declares the sector "getURL" (Yes I am in way too deep with my coding knowledge) Cheers though for really trying to help me out! – Jakob Håkansson Dec 27 '12 at 23:36
  • I might have solved it, the only question for me is: "[self.locationManager stopUpdatingLocation];" "locationManager" is not found (ofc), so what shall it say instead according to my coding? – Jakob Håkansson Dec 27 '12 at 23:44
  • Thought I solved it but I got to to a Breakpoint 2.1... – Jakob Håkansson Dec 27 '12 at 23:49