IOS development-Map Display

Source: Internet
Author: User

(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}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.