iOS Developer

ios 地图点击一点获得他的经纬度

2017-03-03  本文已影响136人  天顾有情人_strive

做高德地图的时候有一个需求是需要得到一个点的经纬度进行导航。

1.创建添加手势

-(void)creatGesture{

UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)];

[_mapView addGestureRecognizer:mTap];

}

- (void)tapPress:(UIGestureRecognizer*)gestureRecognizer {

CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];//这里touchPoint是点击的某点在地图控件中的位置

secondLocation = [_mapView convertPoint:touchPoint toCoordinateFromView:_mapView];//这里touchMapCoordinate就是该点的经纬度了

NSLog(@"%f=======%f",secondLocation.latitude,secondLocation.longitude);

}

但是这样的话有个缺点应该是和地图内部的手势冲突了所以加上这个手势以后点击大头针就出不来气泡了。

如果有需要可以找要点击一点添加大头针并且得到他的经纬度。

上一篇 下一篇

猜你喜欢

热点阅读