iOS targeting--corelocation

Source: Internet
Author: User

One: Import frame

#import <CoreLocation/CoreLocation.h>

Two: Set Proxy and properties

<cllocationmanagerdelegate>

@property (nonatomic, strong) Cllocationmanager *locmgr;

Three: Method realization

-(Cllocationmanager *) locmgr

{

#warning Location services are not available

If(![ Cllocationmanager locationservicesenabled]) return nil;

if (! _locmgr) {

Create a location manager

self. Locmgr = [[Cllocationmanager alloc] init];

// set up proxy

Self . Locmgr. delegate = self ;

}

return _locmgr;

}

-(void) Viewdidload {

[Super Viewdidload];

//Start locating the user's location

[self. Locmgr startupdatinglocation];

}

#pragma mark-cllocationmanagerdelegate

/**

* It will be called as long as the user's location is located (very high frequency of calls)

* @param locations: loaded with Cllocation object

*/

-(void) Locationmanager: (cllocationmanager *) Manager didupdatelocations: (nsarray *) Locations

{

1. Remove Position Object

cllocation *loc = [locations firstobject];

2. remove longitude and latitude

cllocationcoordinate2d coordinate = loc.coordinate;

3. print latitude and longitude

NSLog (@ "didupdatelocations------%f%f", coordinate. latitude, coordinate. longitude);

//Stop positioning (power-saving measures: Stop Location Services immediately if you do not want to use location services )

[Manager Stopupdatinglocation];

}

/**

* Calculates the straight line distance between 2 latitude and longitude degrees

*/

-(void) countlinedistance

{

//Calculate The straight line distance between 2 latitude and longitude

cllocation *loc1 = [[cllocation alloc] initwithlatitude: Longitude: $];

cllocation *loc2 = [[cllocation alloc] initwithlatitude: Longitude: $];

cllocationdistance distance = [Loc1 distancefromlocation:loc2];

NSLog (@ "%f", distance);

}

iOS targeting--corelocation

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.