ios开发 百度地图知道经纬度范围怎么圈定
发布网友
发布时间:2022-03-25 23:02
我来回答
共1个回答
热心网友
时间:2022-03-26 00:32
你好,很高兴为你解答。
长按添加图钉
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (void)longPress:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ //这个状态判断很重要
//<a href="https://www.baidu.com/s?wd=%E5%9D%90%E6%A0%87%E8%BD%AC%E6%8D%A2&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nW6Ln1FbnhD3nhnvnjm0IAYqnWm3PW64rj0d0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBt1njR3njn1rHnsnWRLPWT1PWf" target="_blank" class="-highlight">坐标转换</a>
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
//这里的touchMapCoordinate.latitude和touchMapCoordinate.longitude就是你要的经纬度,
NSLog(@"%f",touchMapCoordinate.latitude);
NSLog(@"%f",touchMapCoordinate.longitude);
//30.264998 120.122538 30.285012 120.117989
LocationObject *aLocationObject = [[LocationObject alloc]initWithTitle:@"hello" latitue:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
aLocationObject._subTitleString = @"world";
NSMutableArray *_mapAnnotations = [[NSMutableArray alloc]initWithCapacity:1];
[_mapAnnotations addObject:aLocationObject];
[self.mapView addAnnotations:_mapAnnotations ];
[_mapAnnotations release];
[aLocationObject release];
}
}
希望能帮到你,求采纳。