在MKMapViewDelegate里有个方法
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
这个方法就是在Map移动 后执行,所以我们可以在这里获取移动后地图中心点的经纬度了。
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKCoordinateRegion region;
CLLocationCoordinate2D centerCoordinate = mapView.region.center;
region.center= centerCoordinate;
//中心点坐标
NSLog(@" regionDidChangeAnimated %f,%f",centerCoordinate.latitude, centerCoordinate.longitude);
}
PS:获取用户点击地图某个区域的经纬度
方法如下
在ViewDidLoad里添加tabGuesture
UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)];
[self.mapView addGestureRecognizer:mTap];
-(void)tapPress:(UIGestureRecognizer*)gestureRecognizer
{
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView ];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView ];
//点击位置的经纬度
NSLog(@"%f %f",touchMapCoordinate.latitude, touchMapCoordinate.longitude);
}
网友评论