NSNumber * latitude = [NSNumber numberWithDouble:[[cityDictionary valueForKeyPath:@"coordinates.latitude"]doubleValue]];
NSNumber * longitude = [NSNumber numberWithDouble:[[cityDictionary valueForKeyPath:@"coordinates.longitude"]doubleValue]];
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
I am getting the following error on line # 3 above:
Sending 'NSNumber *__strong' to parameter of incompatible type 'CLLocationDegrees' (aka 'double')
I know it is because I am trying to pass a NSNumber to a place where it expects a double. But casting is not working due to ARC?
The call to [cityDictionary valueForKeyPath:@"coordinates.latitude"]
is already giving you an NSNumber
object. Why convert that to a double and then create a new NSNumber
?
You could just do:
NSNumber *latitude = [cityDictionary valueForKeyPath:@"coordinates.latitude"];
NSNumber *longitude = [cityDictionary valueForKeyPath:@"coordinates.longitude"];
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
If it turns out that [cityDictionary valueForKeyPath:@"coordinates.latitude"]
is actually returning an NSString
and not an NSNumber
, then do this:
CLLocationDegrees latitude = [[cityDictionary valueForKeyPath:@"coordinates.latitude"] doubleValue];
CLLocationDegrees longitude = [[cityDictionary valueForKeyPath:@"coordinates.longitude"] doubleValue];
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
You are sending type NSNumber to a parameter of double. You could consider changing it to CLLocationDegree
's or double
, but if you are using it elsewhere or storing it with core data I would leave it as NSNumber
.
CLLocation *listingLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With