2012-08-09 38 views
2

我需要格式化我的坐标是这样的:如何格式化这样的坐标?

N 61° 14.5919' 
E 23° 28.1751' 

现在我的坐标是这样的:

61.145919 
23.281751 

我的代码:

- (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]; 
} 
+2

[这] [1]的信息可以帮助你。请享用! [1]:http://stackoverflow.com/questions/8851816/convert-decimal-coordinate-into-degrees-minutes-seconds-direction – parilogic 2012-08-09 07:42:34

回答

0

这并不容易。

在你的例子中,你已经有61度的北部和14.5919分钟,没有秒。 (秒钟被分钟中的小数重新识别。)

您必须将分钟转换为厘米。

61 + 14.5919/60将导致61.31983。

您将不得不考虑S以纬度为负值以及W为经度负值。
您的示例恰好具有N和E坐标,这对正值很有效。但你不能认为这是理所当然的。至少不是如果你想要一些通用的解决方案。

因此对于纬度: 如果该值> = 0,则为N,否则为S. 您可以截断度数的逗号后值并添加°。 然后取其余部分并乘以60,并将其用作分钟并添加th'。

.145919 * 60 = 8.75514 - 这是本例中的分钟值。这应该会导致 N 61°8.75514'

由于您的问题与编程问题无关,而与后面的数学有关,所以我会让您从那里开始。

0

请参见下面的代码

int degreesLat = marker.position.latitude; 
double decimalLat = fabs(marker.position.latitude-degreesLat); 
int minutesLat = decimalLat*60; 
double secondsLat = decimalLat*3600 - minutesLat*60;