1. Basic concepts of mapkit
- Use the core location framework to obtain the location information of the current device, and use the mapkit framework to display this information.
- When using the map service, you need to add the mapkit. Framework framework
- Most functions of mapkit are completed by mkmapview, which is mainly responsible for map display.
2. Sample Code
Code in. h
#import <MapKit/MapKit.h>@interface MainViewController : UIViewController<MKMapViewDelegate,CLLocationManagerDelegate>@property (strong, nonatomic) IBOutlet MKMapView *mapView;</span>
Code in. m
// Set whether to display the user's current position self. mapview. showsuserlocation = yes; // sets the proxy self. mapview. delegate = self; // set the map display type // mkmaptypestandard standard type // mkmaptypesatellite satellite // mkmaptypehybrid hybrid self. mapview. maptype = mkmaptypestandard; // coordinate cllocationcoordinate2d coord = {40.029254, 116.337254}; // display range precision mkcoordinatespan span = {0.1, 0.1 }; // display region mkcoordinateregion region = {coord, span}; // map location during map initialization [self. mapview setregion: region];
3. Common map delegation Methods
Return to the annotation view (PIN view)
-(Mkannotationview *) mapview :( mkmapview *) mapview viewforannotation :( id <mkannotation>) Annotation
Called when updating the current location
-(Void) mapview :( mkmapview *) mapview didupdateuserlocation :( mkuserlocation *) userlocation;
Select annotation View
-(Void) mapview :( mkmapview *) mapview didselectannotationview :( mkannotationview *) view
Called when the display area of the map changes
-(Void) mapview :( mkmapview *) mapview regiondidchangeanimated :( bool) animated