Convert NSNumber to CLCoordinate
Solution 1
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];
Solution 2
what you want is this:
CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)aATM.Longitude;
coord.latitude = (CLLocationDegrees)aATM.Latitude;
Admin
Updated on June 04, 2022Comments
-
Admin about 2 years
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.