Sometimes we do not need to view the map, but only need their own current location, this time there is no need to use Mapkit, direct access to the location service is good
Apple provides a corelocation framework to do the positioning function
First you want to import the Corelocation framework into your project
It is best to check if the location service is available before the location service opens, it is possible that the user has refused or the user has a problem with the Mobile location module, unable to locate
Location services are managed by Cllocationmanager.
Positioning success and other information is also sent to the object through the agent, in addition to the location often need to use the location of the decoding and anti-decoding (in fact, latitude and longitude and the conversion between place names)
The following example code has basic usage and attention points
#import "ViewController.h"#import<CoreLocation/CoreLocation.h>@interfaceViewcontroller () <CLLocationManagerDelegate>{ //Location Service ManagerCllocationmanager *_locationmanager; //using the geocoding deviceClgeocoder *_geocoder;}@end@implementationViewcontroller/** 1. In the development of LBS class applications, before obtaining the user positioning information, it is important to determine whether the location service allows + locationservicesenabled 2. Turn on positioning to get your current position [_locationmanager Startupdatinglocation]; 3. According to latitude and longitude, know the exact place name Reversegeocodelocation 4. Get to latitude and longitude application by naming: navigation geocodeaddressstring*/- (void) viewdidload{[Super Viewdidload]; if(![Cllocationmanager locationservicesenabled]) {NSLog (@"location service is not available!"); return; } NSLog (@"Location Services available!"); _locationmanager=[[Cllocationmanager alloc] init]; //Locate the user location and start updating the user location//[_locationmanager startupdatinglocation]; //Set up proxy_locationmanager.Delegate=Self ; //instantiating a geocode device_geocoder =[[Clgeocoder alloc] init]; [_geocoder geocodeaddressstring:@"Zhongshan Gate"completionhandler:^ (Nsarray *placemarks, Nserror *error) { for(Clplacemark *placemarkinchplacemarks) {NSLog (@"%@%lu", Placemark, (unsignedLong) placemarks.count); } }];}#pragmaMark-Update Location proxy method#pragmaMark as long as the location changes, will be called, electricity! If status is complete, it is best to close the positioning function in time! - (void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{NSLog (@"location Change:%@", locations[0]); //based on latitude and longitude search (go to Apple backstage to find the exact location, must be connected to use)[_geocoder reversegeocodelocation:locations[0] completionhandler:^ (Nsarray *placemarks, Nserror *error) {NSLog (@"%@", placemarks[0]); }];}@end