3 objective-c core-location coordinates cllocation
我想将数据库中的坐标列表拉入数组(在地图上显示之前).但是,在数据库中,它们的类型为Number,我无法弄清楚如何将它们转换为坐标.
这不起作用:我有一个ATM对象(坐标为atm机器),NSNumbers用于纬度和经度.这是一个索引为i的循环,以便逐个拉出它们.atmsArray已经加载了.
ATM *aATM = [self.atmsArray objectAtIndex:i];
CLLocationCoordinate2D coord=[[CLLocationCoordinate2D alloc] initWithLatitude:(CLLocationDegrees)aATM.Latitude longitude:(CLLocationDegrees)aATM.Longitude];
Run Code Online (Sandbox Code Playgroud)
显示错误:-CLLocationCoordinate2D不是ObjectiveC类名或别名 - 当预期浮点值时使用的-pointer值 - 当预期浮点值时使用的值
我尝试了一些不同的东西,但无法弄清楚.如果需要更多信息,请告诉我.
tox*_*xaq 15
aAtm.Longitude和aAtm.Latitude是NSNumbers,它们是指针,因此不能转换为CLLocationDegrees.您需要使用NSNumbers的double值.
CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)[aATM.Longitude doubleValue];
coord.latitude = (CLLocationDegrees)[aATM.Latitude doubleValue];
Run Code Online (Sandbox Code Playgroud)
你想要的是这个:
CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)aATM.Longitude;
coord.latitude = (CLLocationDegrees)aATM.Latitude;
Run Code Online (Sandbox Code Playgroud)