首先在viewdidload里增加地图的一个触摸事件
UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)];
[self.mapView addGestureRecognizer:mTap];
[mTap release];
事件实现如下:
- (void)tapPress:(UIGestureRecognizer*)gestureRecognizer {
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];//这里touchPoint是点击的某点在地图控件中的位置
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];//这里touchMapCoordinate就是该点的经纬度了
NSLog(@"touching %f,%f",touchMapCoordinate.latitude,touchMapCoordinate.longitude);
if (annotationa) {
[self.mapView removeAnnotation:annotationa];
}
annotationa =[[[DisplayMap alloc] initWithCoordinate:touchMapCoordinate] autorelease];
[self.mapView addAnnotation:annotationa];
}
annotationa自己定义去吧,DisplayMap是我自己定的
在实际的应用中,标准类往往不能够满足实际的需要,编写自定义类的能力往往异常的突出,在满足项目需求的同时又要兼顾稳定性,需要对每个类的深层次进行了解,以便定制。