需要帮助来提高宽容度和经度精度

发布于 2024-12-23 03:07:11 字数 753 浏览 5 评论 0原文

我使用以下代码:

locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

其中 locationManager 是类 CLLocationManager 的对象。

当我提取经纬度时只要:

lat = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
    longt=[[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];

NSLog(@"latitude is:%@",lat);
NSLog(@"longitude is: %@", longt);

那么它打印为:

纬度为:30.6807 经度为:76.726

但我确实需要

纬度:57.645800 经度:11.896000

如您所见,两种情况下小数点都以 00 结尾。

我怎样才能做到这一点?

感谢

iPhone 开发者

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铜锣湾横着走 2024-12-30 03:07:11

您可以尝试使用,

lat = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
longt=[[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];

因为纬度和经度以双精度形式返回。

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.

虐人心 2024-12-30 03:07:11

使用 NSNumber 来存储纬度和经度。然后在 NSLog 中使用 %f 和 NSNumber 的 doubleValue 属性。 NSNumber 或 NSDecimalNumber 将为您提供最大精度。

use NSNumber to store the latitude and longitude. then in NSLog use %f and doubleValue property of NSNumber. NSNumber or NSDecimalNumber will give you maximum precision.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文