iOS Location Services

Source: Internet
Author: User

iOS cannot specify which targeting method to use, depending on the device and the surrounding environment to adopt a set of the best solution.

In the relocation service application, the first time the location information is requested, the user is prompted whether to allow location services to be enabled.

iOS mainly uses three classes to achieve positioning:

1) Cllocationmanager, used to locate service management class, it can provide us with location information and height information.

2) Cllocationmanagerdelegate, which is the Cllocationmanager class of the trust agreement

3) Cllocation. This class encapsulates position and height information

The Desiredaccurecy property of the Cllocationmanager class has 6 values.

Kcllocationaccuracynearesttenmeters, accurate to 10 meters

Kcllocatinaccuracyhundredmeters, precise 100 meters

Kcllocatinaccuracykilometer, accurate to 1000 meters

Kcllocatinaccuracythreekilometer, accurate to 3000 meters

Kcllocatinaccuracybest, highest accuracy when using battery power

Kcllocatinaccuracybestfornavigation, maximum accuracy in the case of navigation

Two agent methods:

Locationmanager:didupdatelocations: Positioning success

Locationmanager:didfailwitherror: Failed to locate

The code is as follows:

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

@interface Locationviewcontroller () <CLLocationManagerDelegate>

@property (nonatomic, Strong) Cllocationmanager * Locationmanager;

@end

@implementation Locationviewcontroller

-(void) Viewdidload {
[Super Viewdidload];

Initialize Locationmanager
Self.locationmanager = [[Cllocationmanager alloc] init];
Self.locationManager.delegate = self;
Self.locationManager.desiredAccuracy = Kcllocationaccuracybest;
Self.locationManager.distanceFilter = 0.1f;
}

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

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

#pragma mark-Proxy method
-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations
{
cllocation * location = [locations Lastobject];
NSLog (@ "%3.5f", location.coordinate.latitude);//Longitude
NSLog (@ "%3.5f", location.coordinate.longitude);//Latitude
NSLog (@ "%3.5f", location.altitude);//height
}

-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error
{
NSLog (@ "error:%@", error);
}

@end

iOS Location Services

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.