Nslocationalwaysusagedescription
Nslocationwheninuseusagedescription
Add Cllocationmanager type properties to self (viewcontroller) at the same time
#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <corelocation/cllocationmanagerdelegate.h > @interface viewcontroller:uiviewcontroller@property (Weak, nonatomic) Iboutlet Mkmapview *mapview; @property ( strong,nonatomic) Cllocationmanager *locationmanage;
then implement the request authorization method:
Self.locationmanage=[cllocationmanager new]; [Self.locationmanage requestalwaysauthorization];
There are two ways to request authorization:
Requestalwaysauthorization always authorizes
Requestwheninuseauthorization when trying to authorize
How to set up tracking
if ([Cllocationmanager locationservicesenabled]) { mapview.maptype=mkmaptypestandard; mapview.delegate=self; Mapview.showsuserlocation=yes; [Mapview setusertrackingmode:mkusertrackingmodefollow animated:yes];//set tracking mode }
There are three ways to track your options.
Mkusertrackingmodenone does not track
Mkusertrackingmodefollow Tracking
Mkusertrackingmodefollowwithheading tracking to get location information and direction information
location information for real-time update tracking
Mkusertrackingmodenone = 0,//the user's location was not followedmkusertrackingmodefollow,//The map follows the user ' s Locationmkusertrackingmodefollowwithheading,
Look at the effect: isn't it cool? But: is the range a little bit bigger?
Set Display range (region)Add the following code:
Mkcoordinateregion viewregion=mkcoordinateregionmakewithdistance (mapview.centercoordinate, +, +); [Mapview setregion:viewregion Animated:yes];
The first line of code sets three parameter meanings: Origin, North and south, things See: iOS Learning--MAP 1 show map + reality map
look at the final effect:
OS Learning-Location Services 4 setting test location Debug Test location
Source: