ios开发 为什么百度地图设置为bmkusertrackingmodenone,就无法定位了
展开全部
长按添加图钉 <pre t="code" l="java">- (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. 120. 30. 120.
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];
}
}
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. 120. 30. 120.
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];
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询