2012-09-26 55 views
0

enter image description here的MKMapView找到位置並顯示給用戶

我知道位置在玫瑰銷稱爲A,它是像圖片...現在我想要做的就是這個。

當我的應用程序的用戶在半徑1公里的紅色圓圈內時,我的應用程序必須說他在艾菲爾鐵塔。

我該怎麼做?我明白我必須找回位置,但在那之後,我怎麼能在當前位置找到距離中心1公里的半徑? 感謝

*編輯* 謝謝我使用

if ([region containsCoordinate:self.map.userLocation.coordinate]) { 
        miTrovoIn = street; 
       } 

但是,如果我不顯示在地圖上我的立場這個代碼不起作用。 如果我檢查我的位置,並分享我的位置,它的工作原理。 如何強制應用程序自動獲取我的位置,而無需用戶的交互? 謝謝

+0

這個排序功能被稱爲地理圍欄。搜索周圍的教程,你一定會找到一個你可以使用的。 – Craig

回答

0

創建一個CLRegion。 從文檔:

The CLRegion class defines a geographical area that can be tracked. When an instance of this class is registered with a CLLocationManager object, the location manager generates an appropriate event whenever the user crosses the boundaries of the defined area.

設置圓心和半徑屬性到你所需的值。調用startMonitoringForRegion:desiredAccuracy。如果您需要測試用戶的位置,而不是使用用戶跨越定義區域邊界時生成的通知,則CLRegion類有一個containsCoordinate:實例方法。

double lat = 48.86; 
double lng = 2.29; 
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(lat, lng); 
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate radius:1000.0 identifier:@"your identifier"]; 

http://developer.apple.com/library/IOs/#documentation/CoreLocation/Reference/CLRegion_class/Reference/Reference.html

+0

嗯,你可以給我一個教程嗎?我無法理解我該如何設置中心和半徑的屬性! –

+0

謝謝我解決了我的問題,但我還有一個小問題...你能幫我嗎?看到我的編輯...再次感謝 –

相關問題