1. Add mapkit.framework frame, add field in Plist, to get user's current position setting
Nslocationalwaysusagedescription
2. Code
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface Viewcontroller () <mkmapviewdelegate>
@property (weak, nonatomic) iboutlet mkmapview *mapkit;
Location Information
@property(nonatomic,strong)cllocation*location;
geocoding Objects
@property(nonatomic,strong)clgeocoder*geocide;
@property(nonatomic,strong)Cllocationmanager*manager;
@end
@implementation Viewcontroller
-(void) viewdidload {
[Super viewdidload];
// type of map display
Mkmaptypestandard: Standard type
Mkmaptypesatellite: satellite model
Mkmaptypehybrid: Mixed model
self. Mapkit. Maptype=mkmaptypestandard;
Tracking user locations in iOS8
if([[uidevice currentdevice]. Systemversion doublevalue]>8.0)
{
self. Manager =[[cllocationmanager alloc]init];
[self. Manager requestalwaysauthorization];
}
// settings do not allow map rotation
self. Mapkit. rotateenabled=NO;
self. Mapkit. Delegate=self;
// set mapkit How to get the user's location
Mkusertrackingmodenone not tracking
MKUSERTRACKINGMODEFOLLOW Tracking
Mkusertrackingmodefollowwithheading track and get the user's direction
self. Mapkit. Usertrackingmode=mkusertrackingmodefollowwithheading;
}
-(clgeocoder*) geocide
{
if (_geocide= =Nil) {
_geocide=[[clgeocoder alloc]init];
}
return _geocide;
}
-(void) Mapview: (mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation
{
// use geocoding to get location , set title
[self. Geocide reversegeocodelocation: userlocation. Location completionhandler: ^ (nsarray *placemarks, nserror *error) {
clplacemark *mark=[placemarks firstobject];
Userlocation. title=mark. Name;
Userlocation. subtitle=mark. Locality;
}];
// Use the map's current location settings to display the area
cllocationcoordinate2d center=userlocation. Location. coordinate;
// Specify the latitude span
mkcoordinatespan span=mkcoordinatespanmake(0.009310,0.007812);
// Specify the display area in the
mkcoordinateregion region=mkcoordinateregionmake(center, span);
// Set display area
[self . Mapkit setregion: region];
}
-(void) Mapview: (mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated
{
// map Area change complete
NSLog(@ "%f,%f",self. Mapkit. Region. Span. Latitudedelta,self. Mapkit. Region. Span. Longitudedelta);
}
@end
The use of Mapkit displays the current location