2012-12-27 49 views
-4

我是一个刚刚开始尝试xcode的业余程序员。 我在Google上搜寻一个答案,在我的应用程序中找到当前问题的答案。 (我会在一点。) 我在这里找到了一个很好的答案在Stackoverflow.com,虽然我不知道如何实现它到我自己的编码。 (联系:Opening native google maps in Xcode我如何实现这个答案,我发现我自己的编码?

被修改:基本上:我使用的TabBar应用中,其中在一个选项卡有一个MapView类,从中可以看到根据编码我有这样的事情混合,卫星等,并一个annunci针脚指向一个显示位置的坐标,当你点击它时你可以看到一个按钮。从这里我不知道该怎么做,因为我想让按钮将您链接到您iphone上的“地图”应用程序,为您提供从当前位置到达目的地的路线。这个问题在我写的链接中被问到。它收到了一个答案,但我不知道如何实现这个我自己的编码。

这是我自己的代码:

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 

干杯!

+3

你的问题是什么? – Till

+0

如何实现我在自己的编码链接中找到的答案。 –

+1

我认为你必须更具体 - 它不清楚你在这里问什么。 – Krease

回答

0

您已经设置了按钮按下时的选择器。只是实施该方法,它应该工作。

-(void)BigBenClicked:(id)sender { 
    NSURL *url = [self getURL]; 
    [[UIApplication sharedApplication] openURL:url]; 
} 
+0

就是这样,我对编码完全陌生,所以我不确定要在哪里实施!呃! –

+0

看我的编辑。实现getURL方法,该方法返回在其他代码中生成的URL。就那么简单。 –

+1

切换:“ - (void)button:(id)sender”? 因为没有可见的@interface来声明扇区“getURL”(是的,我的代码知识太深了) 干杯真的想帮助我! –

相关问题