[IOS]地图的简单应用
2023-09-27 14:29:23 时间
操作步骤:
1.首先创建一个项目,在xib的view中添加一个MapVIew控件,并且导入MapKit.framework和CoreLocation.frameword框架。
![](http://img.blog.csdn.net/20130827180313390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGluZ3hpYW93ZWkyMDEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
操作步骤: 1.首先创建一个项目,在xib的view中添加一个MapVIew控件,并且导入MapKit.framework和CoreLocation.frameword框架。 2.实现ViewController的代码: ViewController.h:
#import CoreLocation/CoreLocation.h @interface DXWViewController : UIViewController CLLocationManagerDelegate @property (retain, nonatomic) IBOutlet MKMapView *mapview; @property(retain,nonatomic)CLLocationManager *manager; @property(retain,nonatomic)CLLocation *location; @property (retain, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
ViewController.m:
3.创建大头针的类: Place.h:
蓬莱仙羽 麦子学院讲师,游戏蛮牛专栏作家,CSDN博客专家,热爱游戏开发,热爱Coding!
操作步骤: 1.首先创建一个项目,在xib的view中添加一个MapVIew控件,并且导入MapKit.framework和CoreLocation.frameword框架。 2.实现ViewController的代码: ViewController.h:
#import CoreLocation/CoreLocation.h @interface DXWViewController : UIViewController CLLocationManagerDelegate @property (retain, nonatomic) IBOutlet MKMapView *mapview; @property(retain,nonatomic)CLLocationManager *manager; @property(retain,nonatomic)CLLocation *location; @property (retain, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
ViewController.m:
#import "DXWViewController.h" #import "Place.h" @interface DXWViewController () @implementation DXWViewController - (void)viewDidLoad [super viewDidLoad]; self.manager = [[CLLocationManager alloc] init]; self.manager.delegate = self; //精度 self.manager.desiredAccuracy = kCLLocationAccuracyBest; [self.manager startUpdatingLocation]; self.mapview.showsUserLocation = YES;
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations self.location = [locations objectAtIndex:0]; [self.labels[0] setText:[NSString stringWithFormat:@"%f\u00B0",self.location.coordinate.longitude]]; [self.labels[1] setText:[NSString stringWithFormat:@"%f\u00B0",self.location.coordinate.longitude]]; [self.labels[2] setText:[NSString stringWithFormat:@"%gm",self.location.horizontalAccuracy]]; [self.labels[3] setText:[NSString stringWithFormat:@"%gm",self.location.altitude]]; [self.labels[4] setText:[NSString stringWithFormat:@"%gm",self.location.verticalAccuracy]]; Place *place = [[Place alloc] init]; place.coordinate = self.location.coordinate; place.title = @"Title"; place.subtitle = @"subTitle"; [self.mapview addAnnotation:place]; //设置精度范围 MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(place.coordinate, 1000, 1000); [self.mapview setRegion:region animated:YES]; - (void)didReceiveMemoryWarning [super didReceiveMemoryWarning]; - (void)dealloc { [_mapview release]; [_labels release]; [super dealloc]; @end
3.创建大头针的类: Place.h:
#import Foundation/Foundation.h #import MapKit/MapKit.h @interface Place : NSObject MKAnnotation @property(copy,nonatomic)NSString *title; @property(copy,nonatomic)NSString *subtitle; @property(assign,nonatomic)CLLocationCoordinate2D coordinate; @end
蓬莱仙羽 麦子学院讲师,游戏蛮牛专栏作家,CSDN博客专家,热爱游戏开发,热爱Coding!
相关文章
- iOS编译过程的原理和应用
- iOS开发者账号总结
- Zscaler:iOS应用泄露的用户数据比Android更多
- ios 清理缓存
- iOS block并发
- iOS——文件操作NSFileManager (创建、删除,复制,粘贴)
- iOS应用开发:什么是ARC?
- iOS应用开发详解
- iOS核心应用设计漏洞,暴露用户Apple ID凭证
- iOS 字典转模型Model
- ios框架中UIResponder的职责链设计模式应用
- iOS和Android的APP启动图标和应用商店截图尺寸
- iOS 应用测试
- 高效的 iOS 应用版本支持方法
- OpenAL播放pcm或wav数据流-windows/ios/android(一)
- 李洪强iOS经典面试题154- 通知与推送
- iOS中的通知
- iOS应用内付费(IAP)开发步骤列表
- iOS开发UI篇—无限轮播(新闻数据展示)
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- iOS开发UI篇—字典转模型
- iOS开发UI篇—transframe属性(形变)
- iOS开发拓展篇—CoreLocation定位服务
- 李洪强iOS开发之OC[008] -创建一个对象并访问实例变量