所以我有一个包含10个条目的数组。每个条目都有一个“CustomeObj”类型的对象。在每个对象中,我存储了NSString和CLLocation var。 (例如:“John”,“(23.33f,-32.44f))作为地图参考。
现在,我想在CLLocation变量中访问这些数字:
NSLog(@“%f”,obj.cllVar->纬度);返回0,0000,但调试器中的实际lat var具有实际值。是否有一个双重连接的wat:“obj.cllVar.lat”或是否有另一种拉动lat或long的方法。在cllVar中使用不同的运算符
非常感谢。
答案 0 :(得分:4)
深入了解CLLocation
获取包含lat& amp;的CLLocationCoordinate2D经度:
CLLocation *location = ...
CLLocationDegrees latitude = location.coordinate.latitude;
CLLocationDegrees longitude = location.coordinate.longitude;
答案 1 :(得分:1)
locations and maps programming guide可以为设备位置提供很多帮助。 Techtopia还提供了tutorial关于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;
}