"Implement Features":
1. Show a simple map
2. Display the user's current location
3. Control the View size
4. PIN Click to display information
"Implementation Steps"
1. Import two required frames: Corelocation.framework and Mapkit.framework
2. Introduce the header file:
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
3. A variable of two classes is required, defined here as a property:
@property (nonatomic, retain) Mkmapview *mapview;
@property (nonatomic, retain) Cllocationmanager *locamanager;
4. Don't forget to accept the agreement
@interface Viewcontroller () <cllocationmanagerdelegate,mkmapviewdelegate>
5.OK Start the Code
1- (void) viewdidload{2 [Super Viewdidload];3 4 //Initialize location Management5Self.locamanager =[[Cllocationmanager alloc] init];6 //if the device is in iOS8 and above, you have to give the user authorization before you can get the location permission .7 if([[Uidevice currentdevice].systemversion Doublevalue] >=8.0) {8 [Self.locamanager requestwheninuseauthorization];9 }Ten //Set up proxy OneSelf.locamanager.Delegate=Self ; A //Start Positioning - [Self.locamanager startupdatinglocation]; - the - //Initialize the map view -Self.mapview =[[Mkmapview alloc] initWithFrame:self.view.frame]; - //set map style to basic style (there are three styles here) +Self.mapView.mapType =Mkmaptypestandard; - //whether to display the current location +Self.mapView.showsUserLocation =YES; A //Set up proxy atSelf.mapview.Delegate=Self ; - [Self.view AddSubview:self.mapView]; -}
Implementation of Proxy method
#pragmaMark--mapviewdelegate-(void) Mapviewdidfinishloadingmap: (Mkmapview *) mapview{NSLog (@"Load Complete");}- (void) Mapviewwillstartlocatinguser: (Mkmapview *) mapview{NSLog (@"going to get user location");}- (void) Mapview: (Mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation{//Click on the PIN to show the messageUserlocation.title =@"James Ding"; Userlocation.subtitle=@"Dingjianjaja"; //To move the map view to the user's current location[Mapview setCenterCoordinate:userLocation.location.coordinate Animated:yes]; //set the accuracy and display the user's locationMkcoordinatespan span = Mkcoordinatespanmake (1,1);//scale of 1:10^5,1 cm stands for 1 kmMkcoordinateregion region =Mkcoordinateregionmake (userLocation.location.coordinate, span); [Mapview setregion:region animated:yes];}
6. Running
The discovery does not show the user's location, because the program uses the three status after IOS8, that is, the trial period/always/never, so we need to configure in the Plist file: Trial period or always
Nslocationwheninuseusagedescription
The simple display map has its own location, and the following will continue to join the destination PIN, as well as connect the current location and destination, and calculate the line distance function.
iOS development-Easy to use with Apple's own map