Proficient in iOS development-core location and map Kit

Source: Internet
Author: User

First, the Core location to determine the physical position

Take advantage of the following 3 technologies:

1, GPS (most accurate)

2. Cellular Base Station ID Locator (cell ID location)

3. WPS (Wi-Fi positioning Service,wi-fi location service)

These 3 methods are very power hungry, use the core location to pay attention to this point, as far as possible only when necessary to locate. When used, we can specify the precision as needed. Note that you should be careful when specifying an absolute minimum level of accuracy to avoid unnecessary power consumption.

The technology that the Core location relies on is hidden from the application. We do not need to specify which technology, just specify the level of precision, it will automatically choose from the available technology to better meet the request of the kind.

Second, how to use the core location API?

(i) Create a location manager

The main class to use is Cllocationmanager

Cllocationmanager *locationmanager = [[Cllocationmanager alloc] init];

(ii) Setting accuracy

Avoid specifying any precision that is greater than absolute need

The precision is specified by setting the value of the cllocationaccuracy, and the type is double float, in meters (m)

Example:

Set delegate

Locationmanager.delegate = self;

Request a specific level of accuracy

Locationmanager.desireaccuracy = Kllocationaccuracybest;

If the value of the specified desireaccuracy is 10, the core location is required to be as precise as 10 meters when trying to determine the current position.

Other methods for specifying precision

Kllocationaccuracybestfornavigation

Kllocationaccuracynearesttenmeters

Kllocationaccuracykilometer

Kllocationaccuracythreekilometer

(iii) Setting the distance filter

By default, the location manager notifies delegates of detected location changes. Specifying a distance filter means telling the location manager not to notify you of each change, only if the location change exceeds a certain size.

If set to 1000 m

Locationmanager.distancefilter = 1000.;

If you want the location manager to revert to the default setting without the Selector

Locationmanager.distancefilter = Kcldistancefilternone;

(iv) Access to the use of location services

(v) Start Location Manager

[Locationmanager startupdatinglocation];

(vi) Rational use of the location manager

If you only need to determine the current location without continuous updating, you should let the delegate stop the location manager after you have finished getting the current location information. If polling is required, you need to make sure that polling is stopped if you are willing to do so.

[Locationmanager stopupdatinglocation];

(vii) Get location updates

Use the Locationmanager:didupdatelocations method. The method accepts two parameters

1. Call the location Manager to change the method

2, an array of Cllocation objects that describe the current location of the device, and possibly several previous locations. At any time, the last item of the data represents the current position.

(eight) Use Cllocation to obtain location information

This class has 6 properties that your app might be interested in:

1. Latitude and (longitude) latitude (latitude), coordinate (geographical coordinates)

2, horizontalaccuracy (horizontal accuracy)

3, Altitude (altitude)

4, verticalaccuracy (vertical accuracy)

5. Floor (ground)

6. Timestamp (timestamp)

Example:

Cllocation latitude = theLocation.coordinate.latitude;

(ix) Error notification

If the core location needs to report an error to the application, call Locationmanager:didfailwitherror: 's Delegate method.

1. User denied access: Call and pass the kclerrordenied error code.

2. Unable to determine location: Kclerrorlocationunknown

A Kclerrorlocationunknown error indicates that the problem may be temporary, while a kclerrordenied or other error may indicate that the application will not be able to access the core location for the rest of the current session

Proficient in iOS development-core location and map Kit

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.