ios 开发百度地图怎么通过地址获取经纬度

2025-03-20 19:32:31
推荐回答(2个)
回答1:

- (void)longPress:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ //这个状态判断很重要
//坐标转换
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];

}
}

回答2:

- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view; 复制代码 2.用地图对象的属性来得到 @property (nonatomic) BMKCoordinateRegion region; 复制代码