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!! :)

Alpesh Patoliya
  • 263
  • 1
  • 3
  • 7

3 Answers3

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];
Mashhadi
  • 3,004
  • 3
  • 46
  • 80
Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
  • 1
    `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. – Mark Adams Aug 29 '11 at 21:16
  • 1
    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. – Bill Burgess Aug 29 '11 at 21:19
  • Hi @BillBurgess this answer is worked for me in IOS 6 But IOS 5.1 Its not working... any alternates ... ! – Karthik Apr 29 '13 at 13:29
  • 1
    Probably changed in the last two years but now it should be: `coord.longitude = location.coordinate.longitude; coord.latitude = location.coordinate.latitude;` – cloudsurfin Jul 29 '13 at 04:03
  • 1
    This should be accepted as the correct answer, it is working for me (at least). – higgs241 Aug 23 '13 at 22:55
5

Download this example

this example will show you current lat long

Droid
  • 1,091
  • 2
  • 9
  • 14
0

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

Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
Josua Pedersen
  • 620
  • 1
  • 6
  • 13