3

As far as I know, the max and min values are:
latitude: [-90, 90]
longitude: [-180, 180]

CLLocation still accepts values beyond these limits, for example:

 [[CLLocation alloc] initWithLatitude:100.0 longitude:-200.0];

And the distanceFromLocation: function of CLLocation still returns a valid distance (though we cannot verify this since the coordinates are beyond the limits).

Why is this so?
I am thinking along the following lines:
1. The values beyond those limits correspond to outerspace
2. The values beyond those limits correspond to other dimensions
3. The values beyond those limits remap to a valid value within the range [-90, 90] or [-180, 180].

MiuMiu
  • 1,905
  • 2
  • 19
  • 28

2 Answers2

1

The latitude and longitude is a type of CLLocationDegrees:

//From CLLocation.h
/*
 *  initWithLatitude:longitude:
 *  
 *  Discussion:
 *    Initialize with the specified latitude and longitude.
 */
- (id)initWithLatitude:(CLLocationDegrees)latitude
    longitude:(CLLocationDegrees)longitude;

In which if you observe further is a type of double:

//From CLLocation.h
/*
 *  CLLocationDegrees
 *  
 *  Discussion:
 *    Type used to represent a latitude or longitude coordinate in degrees under the WGS 84 reference
 *    frame. The degree can be positive (North and East) or negative (South and West).  
 */
typedef double CLLocationDegrees;

what is the range of a double in Objective-C?

Hence I believe there is no built in check-in of the value supplied for both latitude and longitude.

Community
  • 1
  • 1
Valent Richie
  • 5,226
  • 1
  • 20
  • 21
  • I am aware that CLLocationDegrees is of type double, but I am curious as to why Apple did not limit the creation of CLLocation to latitude and longitude within the known valid ranges [-90, 90] and [-180, 180] respectively. – MiuMiu May 22 '13 at 03:53
1

Any angles measured in degrees are always modulo 360, so longitude of 380 is mathematically the same as longitude of 20. Regarding latitude, if you think about the angle moving outside the range of [-90,90] in terms of what the picture looks like on a sphere, then you'll see that latitude is modulo 180. So I think your choice number 3 is the right answer.

Stochastically
  • 7,616
  • 5
  • 30
  • 58