How to get current location's longitude and latitude in iOS 4.0/4.2?
Asked Answered
V

3

5

I've problem to obtain current location Longitude and Latitude in iOS 4.0 also tried in iOS 4.2 actually i want to draw route on my apps from current position to specific location, i tried many way in my apps but i can't get result

please reply anyone know about this.

Thanks!! :)

Valois answered 29/8, 2011 at 9:32 Comment(1)
Did you try CLLocationManager?Celenacelene
T
16
CLLocationManager *lm = [[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone; 
[lm startUpdatingLocation];

CLLocation *location = [lm location];

CLLocationCoordinate2D coord;
coord.longitude = location.coordinate.longitude;
coord.latitude = location.coordinate.latitude;
// or a one shot fill
coord = [location coordinate];
Tellurate answered 29/8, 2011 at 21:5 Comment(5)
location will most likely be nil or out of date if you use this approach. The OP should be implementing locationManager:didUpdateToLocation:fromLocation: to receive updates as they come in.Connive
That is true. If they want the best chance for accuracy, they should query the coordinates from inside that method. But this way should at least give them a good start.Tellurate
Hi @BillBurgess this answer is worked for me in IOS 6 But IOS 5.1 Its not working... any alternates ... !Constrain
Probably changed in the last two years but now it should be: coord.longitude = location.coordinate.longitude; coord.latitude = location.coordinate.latitude;Embrangle
This should be accepted as the correct answer, it is working for me (at least).Nisen
M
5

Download this example

this example will show you current lat long

Mayman answered 29/8, 2011 at 9:41 Comment(0)
S
0

You will need to call CLLocationManager (See Apple Documentation). - startUpdatingLocation and - stopUpdatingLocation are one of the main methods you will be using.

Snoop answered 29/8, 2011 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.