苹果地图使用之MKMapView定位显示
2017-01-06 21:33
549 查看
#import <MapKit/MapKit.h> #define kScreenWidht [UIScreen mainScreen].bounds.size.width #define kScreenHeight [UIScreen mainScreen].bounds.size.height @interface ViewController () <MKMapViewDelegate> @property (nonatomic, strong) MKMapView *mapView; @property (nonatomic, strong) CLLocationManager *locationManager; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; _mapView.delegate = self; [_mapView setUserTrackingMode:MKUserTrackingModeFollow]; [self.view addSubview:_mapView]; _locationManager = [[CLLocationManager alloc] init]; [_locationManager requestAlwaysAuthorization]; CLLocationCoordinate2D coordinate = {30.26667, 120.20000}; [_mapView setCenterCoordinate:coordinate animated:YES]; // 定位按钮 UIButton *resetLocationBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, kScreenHeight - 45, 30, 35)]; [resetLocationBtn setBackgroundImage:[UIImage imageNamed:@"location.jpg"] forState:UIControlStateNormal]; [resetLocationBtn addTarget:self action:@selector(resetLocation:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:resetLocationBtn]; } #pragma mark - MKMapViewDelegate - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { // 位置发生变化调用 NSLog(@"lan = %f, long = %f", userLocation.coordinate.latitude, userLocation.coordinate.longitude); } - (void)resetLocation:(id)sender { // 定位到我的位置 [_mapView setCenterCoordinate:_mapView.userLocation.coordinate animated:YES]; } @end
相关文章推荐
- Android 使用百度地图SDK 定位和显示基础地图常见错误 locationclient.start()和mapview is null等等
- MKAnnotationView,MKAnnotation与MKMapView结合使用显示坐标点
- CLLocationManager定位经纬度,MKReverseGeocoder地址解析, MKMapView 地图显示 iphone
- 使用MapView显示地图
- android map api展示地图及和定位结合使用
- 使用地图控件MapView如何申请apiKey
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- 使用MapWinGis控件在桌面应用程序中显示地图
- iOS Cllocationmanger定位, 使用Google Map API在mapview上画路径
- IOS 地图定位,标记位置,获取经纬度,MKMapView的使用
- 【iOS】苹果,百度Map定位使用与总结
- 苹果地图定位和显示区域
- IOS中的地图视图MKMapView
- [IOS] 在MapView中使用地图钉
- [IOS地图开发系类]3、地图视图MKMapview
- ArcGIS For JavaScript API Show map using layer definitions(使用层定义显示地图)————(十三)
- ios-使用ios 6苹果地图定位和跟踪
- [IOS地图开发系类]4、MKMapview上添加MKAnnotationView,标记当前位置
- [ios培训]iOS Cllocationmanger定位, 使用Google Map API在mapview上画路径