将 NSNumber 转换为 CLCooperative

发布于 2024-08-03 07:35:37 字数 541 浏览 9 评论 0原文

我想将数据库中的坐标列表拉入数组中(在地图上显示它们之前)。但是,在数据库中它们的类型是 Number,我不知道如何将它们转换为坐标。

这不起作用: 我有一个 ATM 对象(坐标用于 atm 机器),其中 NSNumbers 表示纬度和经度。这是在一个索引为i的循环中,以便将它们一一拉出来。 atmsArray 已被加载。

ATM *aATM = [self.atmsArray objectAtIndex:i];


CLLocationCoordinate2D coord=[[CLLocationCoordinate2D alloc] initWithLatitude:(CLLocationDegrees)aATM.Latitude longitude:(CLLocationDegrees)aATM.Longitude];

显示错误: -CLLocationCooperative2D 不是 ObjectiveC 类名或别名 - 当需要浮点值时使用的指针值 - 当需要浮点值时使用的指针值

我尝试了一些不同的方法,但无法弄清楚。如果需要更多信息,请告诉我。

I want to pull a list of coordinates from a database into an array (Before displaying them on a map). however, in the database they are of type Number, and I can't figure out how to convert them to coordinates.

This doesn't work:
Where I have an ATM object (The coordinates are for atm machines) with NSNumbers for latitude and longitude. This is in a loop with index i, in order to pull them out one by one. The atmsArray has already been loaded.

ATM *aATM = [self.atmsArray objectAtIndex:i];


CLLocationCoordinate2D coord=[[CLLocationCoordinate2D alloc] initWithLatitude:(CLLocationDegrees)aATM.Latitude longitude:(CLLocationDegrees)aATM.Longitude];

Shows up the errors:
-CLLocationCoordinate2D is not an objectiveC class name or alias
-pointer value used when a floating point value was expected
-pointer value used when a floating point value was expected

I've tried a few different things but can't figure it out. If more information is needed, please let me know.

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

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

发布评论

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

评论(2

涙—继续流 2024-08-10 07:35:37

aAtm.Longitude 和 aAtm.Latitude 是 NSNumber,它们是指针,因此不能转换为 CLLocationDegrees。您需要使用 NSNumbers 的双精度值。

CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)[aATM.Longitude doubleValue];
coord.latitude = (CLLocationDegrees)[aATM.Latitude doubleValue];

根据这个答案

aAtm.Longitude and aAtm.Latitude are NSNumbers which are pointers and as such can't be cast to CLLocationDegrees. You need to use the double values of the NSNumbers.

CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)[aATM.Longitude doubleValue];
coord.latitude = (CLLocationDegrees)[aATM.Latitude doubleValue];

As per this answer

若有似无的小暗淡 2024-08-10 07:35:37

你想要的是这样的:

CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)aATM.Longitude;
coord.latitude = (CLLocationDegrees)aATM.Latitude;

what you want is this:

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