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

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

IOS开发之---地图显示_第1张图片



- (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{
    //不断获取你的精度和新的地址
}




你可能感兴趣的:(ios,null,interface,CLLocation)