CLLocationCoordinate2D center;
MKCoordinateSpan span;
} MKCoordinateRegion;
coord.longitude = 113.346196; //经度
coord.latitude = 23.140563;//纬度
//地图的显示精度,数值越小地图显示越详细
MKCoordinateSpan span;
span.longitudeDelta = 0.1;
span.latitudeDelta = 0.1;
//设置显示区域
- (IBAction)tapAction:(UITapGestureRecognizer*)sender {
CGPoint p = [senderlocationInView:self.view];
//将屏幕上的点转换为地图坐标
CLLocationCoordinate2D coord = [self.mapViewconvertPoint:ptoCoordinateFromView:self.view];
NSLog(@"coord.longitude:%lf coord.latitude:%lf", coord.longitude,coord.latitude);
@property(nonatomic,readonly)CLLocationCoordinate2Dcoordinate;
//选择实现
// Title and subtitle for use by selection UI.
@property(nonatomic,copy)NSString*title;
@property(nonatomic,copy)NSString*subtitle;
- 创建一个继承自MKAnnotationView的自定义大头针视图
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotationreuseIdentifier:reuseIdentifier];
[self addSubview:imageView];
}
return self;
- 当前视图控制器遵守 MKMapViewDelegate协议;
- 设置mapView的委托对象为当前视图控制器(self.mapView.delegate= self或者在Storyboard中拖拽);
- 实现协议方法
static NSString *annotationViewId = @"annotationView";
//从队列中获取一个annotationView
XYZAnnotationView *annotationView = (XYZAnnotationView *)[self.mapViewdequeueReusableAnnotationViewWithIdentifier:annotationViewId];
//如果队列中没有,则创建一个新的annotationView
if (!annotationView) {
annotationView = [[XYZAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:annotationViewId];
}
return annotationView;
1091



被折叠的 条评论
为什么被折叠?



