IOS comes with the targeting feature

Source: Internet
Author: User

First step: Import header File

#import <CoreLocation/CoreLocation.h> #import <CoreLocation/CLLocationManagerDelegate.h>

Step two: Set up the agent

Cllocationmanagerdelegate

Step Three: Create a property

@property (nonatomic, strong) Cllocationmanager *locationmanager;

Fourth Step: Initialize

Location Services Management Object Initialization _locationmanager = [[Cllocationmanager alloc] init];    _locationmanager.delegate = self;    _locationmanager.desiredaccuracy = Kcllocationaccuracybest; _locationmanager.distancefilter = 100.F; Set the minimum move of 1000 meters to refresh

Fifth step: Implement the Proxy method

#pragma mark-Implement location Refresh-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{CLL    Ocation *currlocation = [locations Lastobject]; NSLog (@ "longitude =%f latitude =%f height =%f", CurrLocation.coordinate.latitude, CurrLocation.coordinate.longitude, Currlocation.altitude);}

Sixth step: Start positioning

-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated]; [_locationmanager startupdatinglocation]; Start positioning}

Seventh Step: End positioning

-(void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated]; [_locationmanager stopupdatinglocation]; Stop positioning}


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.