2012-04-07 165 views
0

我的問題是:我如何獲得locationManager座標到我的viewDidLoad方法來加載我的mapview與我以前檢查的位置?如何從locationManager獲取viewDidLoad的座標?

我的LocationManager看着就像這樣(字符串的UILabel):

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    if (wasFound) return; 
    wasFound = YES; 

CLLocationCoordinate2D loc = [newLocation coordinate]; 


latitude.text = [NSString stringWithFormat: @"%f", loc.latitude]; 
longitude.text = [NSString stringWithFormat: @"%f", loc.longitude]; 

}

而且我viewDidLoad中是這樣的:

CLLocationCoordinate2D theCoordinate1; 
theCoordinate1.latitude = 37.786996; 
theCoordinate1.longitude = -122.419281; 

所以我想插入我的真實座標經緯度的地方!

謝謝!

回答

1

使CLLocationCoordinate2D loc屬於您的didUpdateToLocation:方法所處的任何對象的屬性。如果它與viewDidLoad代碼的對象相同,則直接使用它。如果它在某個其他類中,請在視圖控制器中對該類提供引用並以此方式獲取屬性。

0

創建一個CLLocationCoordinate2D屬性併爲其賦值。