我得到了你的触摸事件坐标的解决方案,但你必须使用 MKmapView 我粘贴下面的代码
在.h
#import <MapKit/MapKit.h> //import this in your project
//define the objects;
MKMapView *mapView;
CLLocationCoordinate2D coordinate;
不要忘记在你的项目中添加 MapKit.framework
米
- (void)viewDidLoad
{
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];//Release it in dealloc
mapView.delegate=self;
[self.view addSubview:mapView];
[self displayRegion];
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]initWithTarget:self
action:@selector(handleGesture:)];
tgr.numberOfTapsRequired = 1;
[mapView addGestureRecognizer:tgr];
[tgr release];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
return;
CGPoint touchPoint = [gestureRecognizer locationInView:mapView];
coordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView];
NSLog(@"latitude %f longitude %f",coordinate.latitude,coordinate.longitude);
}
-(void)displayRegion
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location;
location.latitude = 22.569722 ;
location.longitude = 88.369722;
region.span=span;
region.center=location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}
我现在测试了这段代码,它给了我正确的值,还有一件事总是试图在设备上而不是在模拟器上测试它。尝试并回复您的结果,我想它现在应该可以解决问题