2011-05-10 40 views
1

如何使用iPhone實施地理圍柵。iPhone的地理圍欄問題

是否有任何庫可用於實現?

我想知道iPhone是否是的多邊形或圓形的服務器定義或OUTSIDE所以如果設備出方指定的範圍內,那麼它應該告訴服務器。

如何執行此類任務。

在此先感謝

回答

3

您可能想要使用CLLocationManager。請參閱CLLocationManagerDelegate。 這裏有兩種方法。

- (void)locationManager:(CLLocationManager *)manager 
     didEnterRegion:(CLRegion *)region; 


- (void)locationManager:(CLLocationManager *)manager 
    didExitRegion:(CLRegion *)region; 
2

有很多方法可以計算出你的內部是多邊形還是外部。最簡單的是通過W. Randolph Franklin使用光線投射法在此功能詳細:

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) 
{ 
    int i, j, c = 0; 
    for (i = 0, j = nvert-1; i < nvert; j = i++) { 
    if (((verty[i]>testy) != (verty[j]>testy)) && 
    (testx < (vertx[j]-vertx[i]) * (testy-verty[i])/(verty[j]-verty[i]) + vertx[i])) 
     c = !c; 
    } 
    return c; 
} 

爲了測試agsint內或外循環,纔算你的距離爲圓心,並確定它是短於半徑如果它。

1

Yeapy,

我已經得到了解決

Here是相同的示例代碼。它顯示了該區域以及如何從該區域找到入口的方法實施。