1

所以我有一个包含 10 个条目的数组。每个条目都有一个“CustomeObj”类型的对象。在每个对象中,我存储了一个 NSString 和一个 CLLocation var。(类似于:“John”、“(23.33f, -32.44f))作为地图参考。

现在,我想访问 CLLocation 变量中的这些数字:

NSLog (@"%f", obj.cllVar->latitude); 返回 0,0000,但调试器中的真正 lat var 具有实际值。是否有双重连接:“obj.cllVar.lat”或者是否有另一种方式来拉拉或拉长。使用不同的运算符从 cllVar 中取出

非常感谢。

4

2 回答 2

4

只需深入了解CLLocation包含 lat & lon 的 CLLocationCoordinate2D:

CLLocation *location = ...
CLLocationDegrees latitude  = location.coordinate.latitude;
CLLocationDegrees longitude = location.coordinate.longitude;
于 2013-11-14T19:30:30.227 回答
1

位置和地图编程指南可以提供很多使用设备位置的帮助。Techtopia 还提供了关于 CLLocationManager 使用的教程。这是一个片段,它引用了一个 CLLocation 变量newLocation.coordinate.latitude和经度newLocation.coordinate.longitude(请参阅来源以获取更多信息):

#pragma mark -
#pragma mark CLLocationManagerDelegate

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
                  fromLocation:(CLLocation *)oldLocation
{
     NSString *currentLatitude = [[NSString alloc] 
                  initWithFormat:@"%g", 
                  newLocation.coordinate.latitude];
     latitude.text = currentLatitude;

     NSString *currentLongitude = [[NSString alloc] 
          initWithFormat:@"%g",
          newLocation.coordinate.longitude];
     longitude.text = currentLongitude;

     NSString *currentHorizontalAccuracy = 
              [[NSString alloc] 
             initWithFormat:@"%g",
             newLocation.horizontalAccuracy];
     horizontalAccuracy.text = currentHorizontalAccuracy;

     NSString *currentAltitude = [[NSString alloc] 
                  initWithFormat:@"%g",                                                          
                  newLocation.altitude];
     altitude.text = currentAltitude;

     NSString *currentVerticalAccuracy = 
              [[NSString alloc] 
              initWithFormat:@"%g",
              newLocation.verticalAccuracy];
     verticalAccuracy.text = currentVerticalAccuracy;

     if (startLocation == nil)
            self.startLocation = newLocation;

     CLLocationDistance distanceBetween = [newLocation
            distanceFromLocation:startLocation];

     NSString *tripString = [[NSString alloc] 
           initWithFormat:@"%f", 
           distanceBetween];
     distance.text = tripString;
}
于 2013-11-14T19:25:48.207 回答