美文网首页iOS Developer
ios 地图点击一点获得他的经纬度

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

作者: 天顾有情人_strive | 来源:发表于2017-03-03 10:29 被阅读136次

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

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);

}

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

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

相关文章

网友评论

    本文标题:ios 地图点击一点获得他的经纬度

    本文链接:https://www.haomeiwen.com/subject/ltplgttx.html