我是一个刚刚开始尝试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
干杯!
你的问题是什么? – Till
如何实现我在自己的编码链接中找到的答案。 –
我认为你必须更具体 - 它不清楚你在这里问什么。 – Krease