如标题所述,我希望在我的应用程序内通过按一个按钮来打开iOS设备中的原生地图应用程序。目前,我已经使用了一个
以下是代码:
MKMapView
来显示从JSON
文件中获取的纬度/经度的简单标记。以下是代码:
- (void)viewDidLoad {
[super viewDidLoad];
}
// We are delegate for map view
self.mapView.delegate = self;
// Set title
self.title = self.location.title;
// set texts...
self.placeLabel.text = self.location.place;
self.telephoneLabel.text = self.location.telephone;
self.urlLabel.text = self.location.url;
**// Make a map annotation for a pin from the longitude/latitude points
MapAnnotation *mapPoint = [[MapAnnotation alloc] init];
mapPoint.coordinate = CLLocationCoordinate2DMake([self.location.latitude doubleValue], [self.location.longitude doubleValue]);
mapPoint.title = self.location.title;**
// Add it to the map view
[self.mapView addAnnotation:mapPoint];
// Zoom to a region around the pin
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(mapPoint.coordinate, 500, 500);
[self.mapView setRegion:region];
当您点击图钉时,会出现一个带有标题和信息按钮的信息框。
这是代码:
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *view = nil;
static NSString *reuseIdentifier = @"MapAnnotation";
// Return a MKPinAnnotationView with a simple accessory button
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
if(!view) {
view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
view.canShowCallout = YES;
view.animatesDrop = YES;
}
return view;
}
我想创建一个方法,当在信息框中点击按钮时,打开地图应用程序并显示从当前用户位置到上方的地图点的路线。这种做法可能吗?还可以自定义该按钮的外观吗?(我是指像放置不同的图像到按钮上,使其看起来像“按我获取方向”那样)。
抱歉,如果这是一个愚蠢的问题,但这是我第一个iOS应用程序,Obj-c是一门全新的语言对我来说。
提前感谢所有回复。