Question

I need to format my coordinates like this:

N 61° 14.5919'
E 23° 28.1751'

Now my coordinates look like this:

61.145919
23.281751

My code:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    latitudeLabel.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
    longitudeLabel.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];   
}
Was it helpful?

Solution

This existing question seems to have suggestions for how to best solve, plus a library that can do it for you: Convert decimal coordinate into degrees, minutes, seconds, direction

OTHER TIPS

It is not that easy.

In your example you have got 61 degrees north and 14.5919 minutes, no seconds. (The seconds are relpresended by the decimals in the minutes.)

You will have to convert the minutes into centi-degrees.

61 + 14.5919/60 will result in 61.31983 .

You will have to consider that S reuslts in negative values for the latitude as well as W does for the longitude.
Your example happens to have N and E coordinates, which works fine with positive values. But you cannot take that for granted. At least not if you want some general solution.

So for the latitude: It is N if the value is >= 0, otherwise it is S. You can trunc the post-comma values for the degrees and add the °. Then take the remainder and multiply it with 60 and use it as the minutes and add th '.

.145919 * 60 = 8.75514 - That is your minutes value for this example. It should result in N 61° 8.75514'

As your question does not relate to a programming issue but is rather a related to the math behind, I'll let you go from there.

please Refer following code

int degreesLat = marker.position.latitude;
double decimalLat = fabs(marker.position.latitude-degreesLat);
int minutesLat = decimalLat*60;
double secondsLat = decimalLat*3600 - minutesLat*60;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top