IOS Cllocationmanager Targeting

Source: Internet
Author: User

This article reprinted to Http://www.tuicool.com/articles/7JBRZn

In previous versions of IOS8, we had no problem using cllocationmanager positioning, and recently in the IOS8 system it was not possible to locate .... This is a big problem!

<corelocation/corelocation.h> 
@property (nonatomic, strong) Cllocationmanager  *locationmanager;
2. Initialize the Cllocationmanager and start positioning
Locationmanager=[[cllocationmanager alloc] init];    Locationmanager. delegate=self;    Locationmanager.desiredaccuracy=kcllocationaccuracybest;    Locationmanager.distancefilter=;     [Locationmanager startupdatinglocation]; //Open position  
3, the implementation of Cllocationmanagerdelegate agent method
#pragma Mark Cllocationmanagerdelegate/*** get latitude and longitude */-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{Cllocation *currlocation=[locations Lastobject];Location.strlatitude=[nsstring stringwithformat:@ "%f", CurrLocation.coordinate.latitude];  location.strlongitude=[nsstring stringwithformat:@ "%f", CurrLocation.coordinate.longitude];  NSLog (@ "La---%f, lo---%f", currLocation.coordinate.latitude, CurrLocation.coordinate.longitude);} /** * location failed, callback this method */-(void) Locationmanager: (Cllocationmanager *) Manager Didfailwitherror: (Nserror *) error{ if ([error code]==kclerrordenied) { Span class= "indent" >  NSLog (@ "Access Denied"); }  if ([Error Code]==kclerrorlocationunknown) {  NSLog (@ "Cannot get location information"); }}      

Using corelocation positioning in iOS8

1, before the use of corelocation need to call the following function "IOS8 dedicated": iOS8 some changes to the location, including the method of locating authorization, Cllocationmanager added the following two methods: (1) Always allow access to location information
-(void) requestalwaysauthorization;
(2) Allow access to location data during use of the application
-(void) requestwheninuseauthorization;
   Examples are as follows:
Locationmanager=[[cllocationmanager alloc] init];   Locationmanager.  delegate=self;   locationmanager.desiredaccuracy=kcllocationaccuracybest ;  Locationmanager.distancefilter=;  if (iosversion>=8) { [Locationmanager requestwheninuseauthorization];  Allow access to location data in the course of the program (iOS8 positioning required) } [Locationmanager startupdatinglocation];  Turn on positioning           
2. Add the following configuration in the Info.plist file: (1) nslocationalwaysusagedescription (2) nslocationwheninuseusagedescription

After this is added, the positioning function will be able to use the normal!

IOS Cllocationmanager targeting

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.