IOS positioning service

Source: Internet
Author: User

Http://blog.csdn.net/csj1987/article/details/6657468

The core location in IOS provides the positioning function to locate the current coordinates of the device and obtain the device movement information. Because the polling of the positioning device consumes a lot of power, it is best to start it only when necessary.

Among them, the most important class is cllocationmanager, positioning management.

There are three methods for positioning:

1. GPS, the most accurate positioning method, seems to be not supported by iPhone 1.

2. Triangular positioning of cellular base stations. Such positioning is more accurate in cities where signal base stations are relatively confidential.

3. WiFi, which seems to be the data obtained through the database of the network operator, is the most inaccurate in the three types of positioning

Usage:

1. Introduce the corelocation package. Generally, it is not in the default template, so you need to import it manually.

2. Start the location service by starting the cllocationmanager, because the location information needs to be round-robin, and it takes some time for the program to get it, therefore, most of the operations of cuyu lcationmanager are performed by delegation.

Code for loading locationmanager:

[Plain]View
Plaincopy

  1. Cllocationmanager * locationmanager = [[cllocationmanager alloc] init]; // create a location manager
  2. Locationmanager. Delegate = self;
  3. Locationmanager. desiredaccuracy = kcllocationaccuracybest;
  4. Locationmanager. distancefilter = 1000.0f;
  5. // Start position update
  6. [Locationmanager startupdatinglocation];

Desiredaccuracy is set to the positioning precision. It can be set to the optimum, and the device will automatically locate it in the most accurate way.

Distancefilter is a distance filter. To reduce the number of polling times on the positioning device, the location change will not notify the delegate every time, but will only notify the delegate program when enough distance is moved, its unit is meters. Here it is set to move at least 1000 and then notify the delegate to process updates.

Startupdatinglocation is used to start positioning management. In general, it is best to disable it when you do not need to update the positioning, and use stopupdatinglocation to save power.

The most common method for entrusting cllocationmanagerdelegate is:

-(Void) locationmanager :( cllocationmanager *) Manager
Didupdatetolocation :( cllocation *) newlocation
Fromlocation :( cllocation *) oldlocation;

This method is used to locate the method that the delegate will execute when the change is made.

We can get the new location, the old location, and the cllocation contains the coordinates of the longitude and latitude,

At the same time, cllocation also has a horizontalaccuracy attribute to obtain horizontal precision. Its size is the radius of positioning accuracy, in meters.

If the value is-1, the positioning is untrusted.

Another common method of delegation is

-(Void) locationmanager :( cllocationmanager *) Manager
Didfailwitherror :( nserror *) error;

This method is called when an error is found.

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.