I have following method which is failing . I think I am comparing double with int but do know the best approach.
-(BOOL)isValidCoordinate:(CLLocationCoordinate2D)coordinate
{
//Always fail first condition here.
if (coordinate.latitude > -90 && coordinate.latitude< 90) {
[NSException raise:@"Invalid latitude value" format:@"Latitude of %d is invalid", coordinate.latitude];
}
if (coordinate.longitude > -180 && coordinate.longitude < 180) {
[NSException raise:@"Invalid longitude value" format:@"Longitude of %d is invalid", coordinate.longitude];
}
[NSException raise:@"Invalid longitude value blash " format:@"Longitude of %d is invalid asd", coordinate.longitude];
return TRUE;
}
Your comparison should work. The compiler will convert the integer to a floating point number before comparing. If you want to be sure you can change it to:
But your main problem, I think, is that you’re reporting the wrong numbers.
%din a format string tells it to print an integer. You need to tell it to output a floating point number: