-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations
{
Here locations stores the constant updated location coordinate value, takes the last value to the latest position, and if you do not want it to keep updating the location, then get a value in this method and let Locationmanager stopupdatinglocation
Cllocation *currentlocation = [locations Lastobject];
Get the name of your current city
Clgeocoder *geocoder = [[Clgeocoder alloc] init];
Reverse geo-compilation of address information based on latitude and longitude
[Geocoder reversegeocodelocation:currentlocation completionhandler:^ (Nsarray *array, Nserror *error)
{
if (Array.count > 0)
{
Clplacemark *placemark = [array objectatindex:0];
All the information you get is displayed on the label
NSLog (@ "%@", placemark.locality);
[[Nsuserdefaults Standarduserdefaults] setValue:placemark.locality forkey:@ "Placemarkname"];
Get the city
NSString *city = placemark.locality;
if (!city) {
//
The city information of the four municipalities can not be obtained by locality, but only by obtaining the province's method (if it is empty, it is known as the municipality)
//
City = Placemark.administrativearea;
//
// }
//
Self.cityname = City;
//
// }
//
else if (Error = = Nil && [array count] = = 0)
//
// {
//
NSLog (@ "No results were returned.");
//
// }
//
else if (Error! = nil)
//
// {
//
NSLog (@ "An error occurred =%@", error);
//
}
//
}];
The system will keep updating the data until you choose to stop the update, because we just need to get the latitude and longitude, so get it and stop the update.
[Manager Stopupdatinglocation];
}
IOS system map Get current city