博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用地图显示我的位置
阅读量:5046 次
发布时间:2019-06-12

本文共 2914 字,大约阅读时间需要 9 分钟。

#import 
#import
#import
@interface mylocation : UIViewController
@property (retain, nonatomic) IBOutlet MKMapView *m_map;- (IBAction)return:(id)sender;@end

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view from its nib.    self.m_map.showsUserLocation=YES;    CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器    locationManager.delegate=self;//设置代理    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别    locationManager.distanceFilter=1000.0f;//设置距离筛选器    [locationManager startUpdatingLocation];//启动位置管理器    MKCoordinateSpan theSpan;    //地图的范围 越小越精确    theSpan.latitudeDelta=0.05;    theSpan.longitudeDelta=0.05;    MKCoordinateRegion theRegion;    theRegion.center=[[locationManager location] coordinate];    theRegion.span=theSpan;    [self.m_map setRegion:theRegion];    [locationManager release];}

设置标注

- (IBAction)FindUs:(id)sender {    self.UsMap.hidden = NO;    CLLocationCoordinate2D coord;    coord.latitude = 34.7993;    coord.longitude = 113.6939;    POI *poi = [[POI alloc]initWithCoords:coord];   [UsMap addAnnotation:poi];         MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };    theRegion.center=coord;    [UsMap setZoomEnabled:YES];    [UsMap setScrollEnabled:YES];    theRegion.span.longitudeDelta = 0.01f;    theRegion.span.latitudeDelta = 0.01f;    [UsMap setRegion:theRegion animated:YES];}

@interface POI : NSObject 
{ CLLocationCoordinate2D coordinate; NSString *subtitle; NSString *title; } @property (nonatomic,readonly) CLLocationCoordinate2D coordinate; @property (nonatomic,retain) NSString *subtitle; @property (nonatomic,retain) NSString *title; -(id) initWithCoords:(CLLocationCoordinate2D) coords; @end

@implementation POI   @synthesize coordinate,subtitle,title;   - (id) initWithCoords:(CLLocationCoordinate2D) coords{           self = [super init];           if (self != nil) {                   coordinate = coords;                }           return self;       }   - (void) dealloc   {       [title release];       [subtitle release];       [super dealloc];   }   @end
/获取位置信息    CLGeocoder *geocoder = [[CLGeocoder alloc] init];    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray* placemarks,NSError *error)    {        if (placemarks.count >0   )        {            CLPlacemark * plmark = [placemarks objectAtIndex:0];                        NSString * country = plmark.country;            NSString * city    = plmark.locality;                                    NSLog(@"%@-%@-%@",country,city,plmark.name);            self.m_locationName.text =plmark.name;        }                NSLog(@"%@",placemarks);            }];        //[geocoder release];

转载于:https://www.cnblogs.com/zzzili/archive/2012/12/29/6662649.html

你可能感兴趣的文章
python3基础06(随机数的使用)
查看>>
Zookeeper系列(二)特征及应用场景
查看>>
【HTTP】Fiddler(三)- Fiddler命令行和HTTP断点调试
查看>>
Spring Boot使用Druid和监控配置
查看>>
poi 处理空单元格
查看>>
Android 内存泄漏优化总结
查看>>
luogu4849 寻找宝藏 (cdq分治+dp)
查看>>
Spring Cloud微服务笔记(五)Feign
查看>>
C语言键盘按键列表
查看>>
Codeforces Round #374 (Div. 2)
查看>>
oracle数据类型
查看>>
socket
查看>>
Vue中使用key的作用
查看>>
二叉索引树 树状数组
查看>>
日志框架--(一)基础篇
查看>>
Java设计模式之原型模式
查看>>
Spring学习(四)-----Spring Bean引用同xml和不同xml bean的例子
查看>>
哲理故事与管理之道(20)-用危机激励下属
查看>>
关于源程序到可运行程序的过程
查看>>
wepy的使用
查看>>