IOS system map Get current city

Source: Internet
Author: User

-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.