Convert NSNumber to CLCoordinate

I want to list the coordinates from the database in an array (before displaying them on the map). however, in the database they are of type Number, and I cannot figure out how to convert them to coordinates.

This does not work: Where do I have an ATM object (coordinates for atm computers) with NSNumbers for latitude and longitude. This is in a loop with index i to pull them out one by one. AtmsArray is already loaded.

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


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

It shows errors: -CLLocationCoordinate2D is not a class or alias name objectC - pointer value used when a floating point value was expected - parameter value used when a floating point value was expected

I tried several different things, but I can not understand. If you need more information, please let me know.

+3
source share
2 answers

aAtm.Longitude and aAtm.Latitude are NSNumbers, which are pointers and therefore cannot be translated into CLLocationDegrees. You need to use double NSNumbers.

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

In accordance with this answer

+14
source

What would you like:

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

Source: https://habr.com/ru/post/1716576/


All Articles