2013-05-22 27 views
2

據我所知,最大和最小的值是:
緯度:[-90,90]
經度:[-180,180]CLLocation接受經度和緯度大於或小於其最大值和最小值

CLLocation仍然接受價值超過這些限制,例如:

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

而且CLLocation的distanceFromLocation:功能仍然會返回一個有效距離(雖然我們無法確認這一點,因爲座標是超越極限)。

這是爲什麼?
我大致如下思想:超出極限
1的值對應於外太空
2.超出範圍的值對應於其它尺寸
3.超出限度的值重新映射到一個有效的值的範圍內範圍[-90,90]或[-180,180]。

回答

1

的緯度和經度是一種CLLocationDegrees的:

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

如果您在其中進一步觀察是一種雙:

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

因此,我相信有沒有建立在緯度和經度上提供的值的簽入。

+0

我知道CLLocationDegrees的類型是double,但我很好奇,爲什麼Apple沒有限制CLLocation在已知有效範圍[-90,90]和[-180,180]內的經度和緯度的創建。分別。 – MiuMiu

0

以度爲單位測量的任何角度總是以模360爲模,因此380的經度在數學上與經度爲20相同。關於緯度,如果考慮角度在[-90,90]範圍之外移動在一個球體上看起來像什麼,然後你會看到緯度是180模。所以我認爲你的選擇3是正確的答案。

相關問題