2012-04-07 303 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属性并为其赋值。