您可以通过以下代码来开启定位功能:
-
- [_mapView setShowsUserLocation:YES];
定位成功后,可以通过mapView.userLocation来获取位置数据。
您也可以通过以下代码来使用定位三态效果,包括普通态、跟随态和罗盘态:
-
- -(IBAction)startLocation:(id)sender
- {
- NSLog(@"进入普通定位态");
- _mapView.showsUserLocation = NO;
- _mapView.userTrackingMode = BMKUserTrackingModeNone;
- _mapView.showsUserLocation = YES;
- }
-
-
- -(IBAction)startFollowing:(id)sender
- {
- NSLog(@"进入跟随态");
- _mapView.showsUserLocation = NO;
- _mapView.userTrackingMode = BMKUserTrackingModeFollow;
- _mapView.showsUserLocation = YES;
- }
-
-
- -(IBAction)startFollowHeading:(id)sender
- {
- NSLog(@"进入罗盘态");
- _mapView.showsUserLocation = NO;
- _mapView.userTrackingMode = BMKUserTrackingModeFollowWithHeading;
- _mapView.showsUserLocation = YES;
- }
完整的示例代码请参考相关下载demo工程中的LocationDemoViewController.mm文件
示例效果如下:
