-4

私は最近 xcode を試し始めたばかりのアマチュア プログラマーです。アプリで現在の問題に対する答えを見つけようとして、グーグルで検索していました。(これについては後で説明します。) そして、ここ Stackoverflow.com で優れた回答を見つけましたが、それを自分のコーディングに実装する方法はわかりません。(リンク: Xcode でネイティブ Google マップを開く)

編集:基本的に:私はタブバーアプリケーションを使用しています。1つのタブにマップビューがあり、ハイブリッド、衛星などのコーディングに従って見ることができ、場所を示す座標への注釈ピンがあります。クリックするとボタンが表示されます。そして、私が何をすべきかわからないのはここからです。ボタンを使用して 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

乾杯!

4

1 に答える 1

0

ボタンが押されたときのセレクターはすでに設定されています。メソッドを実装するだけで、機能するはずです。

-(void)BigBenClicked:(id)sender {
    NSURL *url = [self getURL];
    [[UIApplication sharedApplication] openURL:url];
}
于 2012-12-27T23:16:54.880 に答える