【问题标题】:How to send CLLocationCoordinate2D var to another file?如何将 CLLocationCoordinate2D var 发送到另一个文件?
【发布时间】:2011-05-20 14:20:13
【问题描述】:

我是 obj-c 和 iOS 编程的新手。 所以在一个文件/模块中我编写了 GPS+地图,在这个文件/模块中我更新了我的地理位置。 在另一个文件/模块中,我有函数将第一个文件/模块的地理位置作为 CLLocationCoordinate2D var。有小代码部分可以解释我的意思。 GPS+地图文件中的一些功能是:。

-(void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation {
  if (AnotherModuleGeolocTaker!=nil) 
     [[AnotherModuleGeolocTaker getInstance] setLocation:[userLocation coordinate]];
...

有地理定位。二传手。在另一个文件/module.h:.

...
@property (nonatomic, assign) CLLocationCoordinate2D location;
...

在另一个文件/module.m:.

...
@synthesize location;
...
- (IBAction)ThereIsGeolocTakeAction:(id)sender {
    NSLog(@"\n\nlatitude = %g\n\tlongitude = %g",location.latitude,location.longitude);
...

那么如何将坐标从 'didUpdateUserLocation' 发送到 'ThereIsGeolocTakeAction' ?

【问题讨论】:

    标签: objective-c xcode ios geolocation


    【解决方案1】:

    IBAction 用于连接 Interface Builder 中的按钮,因此当用户点击该按钮时,它会触发方法调用。你不想在这里。你只需要一个常规的方法。

    在地图文件中,在 didUpdateUserLocation 内部:实现以下代码:

    if (AnotherModuleGeolocTaker!=nil) {
        [[AnotherModuleGeolocTaker getInstance]
             ThereIsGeolocTakeAction:[userLocation coordinate]];
     }
    

    在 AnotherModuleGeolocTaker.m 中实现这个方法:

     -(void)ThereIsGeolocTakeAction:(CLLocationCoordinate2D)theNewLocation {
         NSLog(@"\n\nlatitude = %g\n\tlongitude = %g",
                  theNewLocation.latitude,theNewLocation.longitude);
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      相关资源
      最近更新 更多