IOS GPS Tracking Notes

Source: Internet
Author: User

Cllocationmanager also provides the following class of methods to determine the location-related service status of the current device.

ø+ locationservicesenabled: Returns whether the current location service is available.

ø+ deferredlocationupdatesavailable: Returns whether the deferred location update is available.

ø+ significantlocationchangemonitoringavailable: Returns a significant position to change whether the listener is available.

ø+ headingavailable: Returns whether the device supports magnetometer calculation direction.

ø+ israngingavailable: Returns whether the Bluetooth signal range service is available. This is the new method for iOS 7.

In addition to this, you can set the following properties for this object before using Cllocationmanager to start positioning.

Øpauseslocationupdatesautomatically: Sets whether the iOS device can pause positioning to conserve battery power. If this property is set to "YES", iOS devices can automatically pause positioning when the iOS device no longer needs to locate data.

Ødistancefilter: Sets the automatic filter distance for the Cllocationmanager. That is, the signal for a position change is generated only if the device changes in a horizontal position beyond the distance specified by the value (in meters).

Ødesiredaccuracy: Sets the precision of the location service. This property value supports kcllocationaccuracybestfornavigation (optimal accuracy of the navigation level), kcllocationaccuracybest (best accuracy), kcllocationaccuracy Nearesttenmeters (10 meter error), Kcllocationaccuracyhundredmeters (hundred meter error), Kcllocationaccuracykilometer (km error), Constant values such as kcllocationaccuracythreekilometers (3-kilometer error). Of course, you can also specify a floating-point number directly as the error allowed by the location service.

Øactivitytype: Sets the purpose for locating data. This property supports Clactivitytypeother (location data as a general purpose), clactivitytypeautomotivenavigation (positioning data used as vehicle navigation), Clactivitytypefitness (positioning data is used as a walking navigation) and one of several enumeration values Clactivitytypeothernavigation (positioning data used as other navigation).

------------cllocation
The Cllocation class represents a location information, which also includes direction and speed. For example, I at 188th Changan Street at 5 km/h to go west. Cllocation has the following properties and methods:
@property cllocationcoordinate2d coordinate; Location information expressed in longitude and latitude
@property cllocationdistance altitude; Elevation
@property cllocationaccuracy horizontalaccuracy; Horizontal accuracy (e.g., accurate to m)
@property cllocationaccuracy verticalaccuracy; Vertical accuracy
@property Cllocationdirection Course; Direction
@property cllocationspeed speed; Speed
-(NSDate *) TimeStamp;
Distance between two positions
-(Cllocationdistance) Distancefromlocation: (cllocation *) location;


-------------Cllocationmanager
The Cllocationmanager class manages and provides location services. Its properties and methods are:
@property cllocation *location; Position
@property id<cllocationmanagerdelegate> Delegate;
@property cllocationdistance Distancefilter; Distance filtering, for example: within 500
@property cllocationaccuracy verticalaccuracy; Vertical accuracy
-(void) startupdatinglocation; Start updating the location (e.g., you're going somewhere)
-(void) stopupdatinglocation; Stop Update location
-(void) startupdatingheading; Start updating directions (e.g., you go East)
-(void) stopupdatingheading; Stop Update Direction
Cllocationmanagerdelegate is a delegate class. Your application needs to use this delegate class. When the user changes the location, the Cllocationmanager callback method is:
-(void) Locationmanager: (Cllocationmanager *) Manager didupdatetolocation: (cllocation *) newlocation fromlocation: ( Cllocation *) oldlocation;
When the user changes direction, the method that is called is:
-(void) Locationmanager: (Cllocationmanager *) Manager didupdateheading: (cllheading *) newheading;
When the iphone is unable to get information about its current location, the callback method is:
-(void) Locationmanager: (Cllocationmanager *) Manager didfailloadwitherror: (nserror *) error;


=========================================================================
Let's take a look at the basic steps for a location class:
First, start the location service
Cllocationmanager *locmanager = [[Cllocationmanager alloc] init];
Locmanager.delegate = self;
[Locmanager startupdatinglocation];
Second, get location information
-(void) Locationmanager: (Cllocationmanager *) Manager
Didupdatetolocation: (cllocation *) newlocation fromlocation: (cllocation *) oldlocation
{
Nstimeinterval howrecent = [Newlocation.timestamp Timeintervalsincenow];
if (Howrecent < -10) return;//less than 10 seconds from last update
if (Newlocation.horizontalaccuracy >) return; Accuracy > 100 m
Longitude and latitude
Double lat = newLocation.coordinate.latitude;
Double lon = NewLocation.coordinate.longitude;
}
Third, to obtain direction information (for example, go south)
-(void) Locationmanager: (Cllocationmanager *) Manager didupdateheading: (clheading *) newheading
{
Get Directions
Cllocationdirection heading = newheading. trueheading;
}
Four, stop positioning
[Locmanager stopupdatinglocation];
You can set the precision and distance filters you want:
Locmanager.desiredaccuracy = Kllocationaccuracybest;
Locmanager.distancefilter = 1000;

IOS GPS Tracking Notes

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.