(1) first, pull a mapview to your project.
(2) Add the following to your 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
Remember
IBOutlet
Must be added, and you need to connect mapview in your XIB to this attribute definition, otherwise it will be troublesome.
The implementation code in controller. m is as follows:
In the viewdidload function
- (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]; // }
And implement functions:
-(Mkannotationview *) mapview :( mkmapview *) mapview viewforannotation :( id <mkannotation>) Annotation
This function is used to display your map, and you can use the positioning symbol in it to locate your location.
- (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;}
And functions
-(Void) locationmanager :( cllocationmanager *) managerdidupdatetolocation :( cllocation *) newlocation fromlocation :( cllocation *) oldlocation {// get your precision and new address Continuously}