使用MapKit框架(持续更新)
2014-05-15 09:54
211 查看
使用MapKit框架
RootViewController.m
// // RootViewController.m // CoreLocation // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" #import <MapKit/MapKit.h> @interface RootViewController ()<CLLocationManagerDelegate> @property (nonatomic, strong) CLLocationManager *locationManager; @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // 判断定位功能是否可以使用 if([CLLocationManager locationServicesEnabled]) { // 初始化定位管理器 _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; // 开始定位 [_locationManager startUpdatingLocation]; } else { NSLog(@"定位功能不可用"); } } - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { // 获取坐标信息 CLLocation *newLocation = [locations lastObject]; // 定位结束 [manager stopUpdatingLocation]; // 初始化地图控件 MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; // 地图的类型 mapView.mapType = MKMapTypeStandard; // 视图的宽度和高度将和父视图的宽度一起成比例变化 mapView.autoresizingMask = \ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // 显示用户所在位置(此处系统会询问你是否使用当前位置) mapView.showsUserLocation = YES; // 地图缩放级别 MKCoordinateSpan span = {0.02, 0.02}; // 被显示的区域 MKCoordinateRegion region = {newLocation.coordinate, span}; // 设置显示的区域 [mapView setRegion:region]; // 显示地图 [self.view addSubview:mapView]; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"%@", error); // 定位结束 [manager stopUpdatingLocation]; } @end
RootViewController.m
相关文章推荐
- 使用MapKit框架(持续更新)
- Microsoft.Practices.EnterpriseLibrary for .Net2.0使用中的问题(相关问题持续更新)
- Sql Server 2005 使用技巧小结(持续更新)
- .NET 程序员面试题(持续更新)至少100多公司使用过的面试题[经典中的经典]
- 初学Ubuntu10.10使用问题解决办法(持续更新...)
- fedora linux 使用笔记(持续更新)
- iptables 使用技巧(持续更新中)
- Rational license命令行使用-持续更新中
- mysql 使用相关 持续更新中...
- Qt学习重要知识点简记---控件使用篇(持续更新)
- HDL编程使用verilog代码而非逻辑框图的原因--持续更新
- 使用Vista的一些问题[持续更新]
- SilverLight2 Beta2 使用中发现的Bug及解决方案(持续更新)
- stl使用小结(持续更新中)
- Delphi使用心得------持续更新中
- 使用libnet构造源mac持续更新的arp攻击程序
- C++使用小结(持续更新中)
- 功能强大的打包工具 NSIS,全部用脚本搞定 使用经验总结帖(持续更新中。。。)
- windowmaker (wmaker)使用笔记> >持续更新
- Altium使用技巧--持续更新