I'm using the below code:
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
Where locationManager
is an object of class CLLocationManager
.
When I'm extracting the lat & long as:
lat = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
longt=[[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
NSLog(@"latitude is:%@",lat);
NSLog(@"longitude is: %@", longt);
then it prints as:
latitude is:30.6807 longitude is: 76.726
but I do need as
Lat: 57.645800 Long: 11.896000
As you see the decimal ends with 00 in both cases.
How can I do that??
Thanks
iPhoneDeveloper
You can try using
lat = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
longt=[[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];
as latitude and longitude are returned as double.