正如标题所述,我想通过按一个按钮从我自己的应用程序中打开 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;
}
当单击上面信息框中的按钮时,我想创建一个方法来打开地图应用程序,其中包含从当前用户位置到上面 mapPoint 的方向。那可能吗?我还可以自定义此按钮的外观吗?(我的意思是把不同的图像放到按钮上,让它看起来像“按我的方向”)。
对不起,如果这是一个愚蠢的问题,但这是我的第一个 ios 应用程序,Obj-c 对我来说是一种全新的语言。
提前感谢所有回复。