How can I obtain the coordinates of my current position on the iPhone?

Source: Internet
Author: User

How can I obtain the coordinates of my current position on the iPhone?

1. First

# Import<Corelocation/corelocation. h>

 

 

2. Two variables are defined in the class:

Cllocationmanager*Locationmanager;

Cllocationcoordinate2dCurlocation;

 

3. Class implementationCllocationmanagerdelegate proxy.

 

 

 

4. ImplementationCode:

 

// Obtain your current location information <br/>-(void) getcurposition <br/>{< br/> // start to test your location <br/> If (locationmanager = nil) <br/>{< br/> locationmanager = [[cllocationmanager alloc] init]; <br/>}</P> <p> If ([cllocationmanager locationservicesenabled]) <br/> {<br/> locationmanager. delegate = self; <br/> locationmanager. desiredaccuracy = kcllocationaccuracybest; <br/> locationmanager. distancefilter = 10.0f; <br/> [locationmanager startupdatinglocation]; <br/>}< br/> 

Startupdatinglocation is the start of the search for the current location. As long as the range of the current location movement exceeds the range specified by distancefilter, the system will receive

The latest coordinate position information.

 

To disable location update, you must call stopupdatinglocation.

 

5. If you get the current user location, there will be a delegate function:

-(Void) Locationmanager :(Cllocationmanager*) Manager didupdatetolocation :(Cllocation*) Newlocation

Fromlocation :(Cllocation*) Oldlocation

Called.

 

// Respond to the update of the current location. Record the latest location here <br/>-(void) locationmanager :( cllocationmanager *) manager didupdatetolocation :( cllocation *) newlocation <br/> fromlocation :( cllocation *) oldlocation <br/>{< br/> nslog (@ "newlocation: % @", [newlocation description]); </P> <p> // Save the new location <br/> curlocation = newlocation. coordinate; <br/>} 

 

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.