5
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?

milof
  • 696
  • 9
  • 25
  • Note that you aren't actually casting anything in that code. (It wouldn't help if you did but, in terms of identifying the current problem, that's not it.) – Phillip Mills Nov 17 '12 at 18:10
  • not sure who is down voting but it is apparent someone is bored. I tried to upvote all those that answered – milof Nov 17 '12 at 18:24

2 Answers2

3

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];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
2

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]];
brightintro
  • 1,016
  • 1
  • 11
  • 16