IOS Development Notes Collation 49 of the detailed positioning Cllocation_ios

Source: Internet
Author: User

In the project function has a positioning cllocation needs, encountered some knowledge and difficulties, after the help of the heroes, problem solving, hereby share for everyone to learn, I hope we learn and progress together.

One, simple explanation

1.CLLocationManager

Common operations and properties for Cllocationmanager

Start user positioning-(void) startupdatinglocation;

Stop user positioning-(void) stopupdatinglocation;

Note: When the Startupdatinglocation method is invoked, the user's position is constantly positioned, and the following method of the proxy is frequently invoked

-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations;

Every number of meters to locate once

@property (Assign, nonatomic) cllocationdistance distancefilter;

Positioning accuracy (the more accurate the more power consumption)

@property (Assign, nonatomic) cllocationaccuracy desiredaccuracy;

With the positioning function, you first import the framework, follow the Cllocationmanagerdelegate protocol, and then create the location manager Cllocationmanager

After the iOS8.0, The positioning feature needs to include the Nslocationwheninuseusagedescription and nslocationalwaysusagedescription two nsstring type fields in Info.plist. To use the positioning function

Code posted out to share with you, you reader self study

{Self.locationmanager = [[Cllocationmanager alloc] init];
  _locationmanager.delegate = self;
  if ([cllocationmanager locationservicesenabled] = no) {//NSLog (@ "No GPS service");
  }//geographic accuracy _locationmanager.desiredaccuracy=kcllocationaccuracynearesttenmeters; Set the distance filter, double type, as long as the distance changes how much, call the delegate agent Self.locationManager.distanceFilter = Kcldistancefilternone;
meters [_locationmanager startupdatinglocation] at the front of the _locationmanager requestwheninuseauthorization];//; }-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations {NSLog (@ "longitude =
  %f ", ((Cllocation *) [Locations Lastobject]). Coordinate.longitude);
    NSLog (@ "latitude =%f", ((Cllocation *) [Locations Lastobject]). Coordinate.latitude);
    CGFloat longti= (cllocation *) [Locations Lastobject]). Coordinate.longitude;
    CGFloat latti= (cllocation *) [Locations Lastobject]). Coordinate.latitude; Displays the longitude to _longitudelabel on the label.Text = [NSString stringwithformat:@ "%f", Longti];
  The latitude reality to the label _latitudelabel.text = [NSString stringwithformat:@ "%f", Latti];
  Get the name of the city that is currently in clgeocoder *geocoder = [[Clgeocoder alloc] init]; Compile the address information according to the longitude and latitude [geocoder reverseGeocodeLocation:locations.lastObject completionhandler:^ (Nsarray *array,       Nserror *error) {if (Array.count > 0) {clplacemark *placemark = [array objectatindex:0];//
       Displays all the information obtained to the label//Self.location.text = Placemark.name;
       Get the city nsstring *city = placemark.locality; if (!city) {//Four municipalities of the city information can not be obtained through the locality, only through the acquisition of provincial methods to obtain (if City is empty, then known as the central Municipality) cities = Placemark.administrative
       area;
       }//NSLog (@ "city =%@", city);
     _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 always be moreNew data until you choose to stop the update because we only need to get a latitude and longitude, so we stop updating [manager Stopupdatinglocation] after we get it. }

The above is about the cloud Habitat Community Small series for everyone to tidy up the development of iOS detailed positioning cllocation, follow-up will continue to update, I hope we can like.

Related Article

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.