将 NSNumber 转换为 CLCooperative
我想将数据库中的坐标列表拉入数组中(在地图上显示它们之前)。但是,在数据库中它们的类型是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
aAtm.Longitude 和 aAtm.Latitude 是 NSNumber,它们是指针,因此不能转换为 CLLocationDegrees。您需要使用 NSNumbers 的双精度值。
根据这个答案
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.
As per this answer
你想要的是这样的:
what you want is this: