Get current location using CLLocationCoordinate2D

Posted by Mobility on Stack Overflow See other posts from Stack Overflow or by Mobility
Published on 2012-03-14T05:25:55Z Indexed on 2012/04/06 5:29 UTC
Read the original article Hit count: 114

I am trying to get current location of user using CLLocationCoordinate2D. I want the values in the format like

CLLocationCoordinate2D start = {-28.078694,153.382844 };

So that I can use them like following:

 NSString *urlAddress = [NSString 
       stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",  
       start.latitude, start.longitude, 
       destination.latitude, destination.longitude];  

I used

CLLocation *location = [[CLLocation alloc]init ];
CLLocationDegrees currentLatitude = location.coordinate.latitude;
CLLocationDegrees currentLongitude = location.coordinate.longitude;

to get current lat & long.

But I am getting 0.000 for both when I try to test. I am testing on iPhone 4s.

If there is any sample code, it will be great.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c