IOS开发之---地图显示

(1)首先拉一个mapView到你的工程

(2)在你的Controller.h中加入:

@interface EXViewController : UIViewController<MKMapViewDelegate,CLLocationManagerDelegate>{
@private 
    MKMapView *_mapView;
    CLLocationManager *_loactionManager;
}

@property(nonatomic, readwrite,retain) IBOutlet MKMapView *mapView;
@property(nonatomic, readwrite, retain)CLLocationManager *locationManager;
@end
记得
IBOutlet
一定要加的,而且要连接你的xib中的mapview到这个属性定义,不然会有麻烦的呵呵。
那么Controller.m中的实现的代码:

在viewDidLoad函数中

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.mapView.delegate = self;
    self.mapView.showsUserLocation = YES;
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    
    [self.locationManager startUpdatingHeading];
    [self.locationManager startUpdatingLocation];
    
    //
    
}

并且实现函数:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

这个函数用来实现你的地图显示,并且可以通过如图中的那个定位符号来定位自己的位置




- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"snda.pin"];
    if (annView == NULL) {
        annView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"snda.pin"] autorelease];
        
    }
    
    annView.annotation = annotation;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(0, 0);
    annView.image = [UIImage imageNamed:@"capture-exposure-plus.png"];
    annView.rightCalloutAccessoryView   = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    
    return annView;
}

和函数

- (void)locationManager:(CLLocationManager *)manager
	didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{
    //不断获取你的精度和新的地址
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值