更改CLLocation的坐标

时间:2009-07-30 20:17:35

标签: cocoa-touch

我是Objective C的新手,所以这可能是一个微不足道的问题:

初始化位置后:

CLLocation *currentPoint = [[CLLocation alloc] initWithLatitude:0 longitude:0]:

我怎样才能改变纬度和经度?

2 个答案:

答案 0 :(得分:11)

以下是如何修改CLLocation的示例:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{


    newLocation = [[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude, -1.1874988592864875)
                                                 altitude:newLocation.altitude
                                       horizontalAccuracy:newLocation.horizontalAccuracy
                                         verticalAccuracy:newLocation.verticalAccuracy
                                            timestamp:newLocation.timestamp] autorelease];

这是另一个如何创建新CLLotation的示例:

CLLocation *newLocation = [[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(41.44994138650804, -1.1874988592864875)
                                                   altitude:0
                                         horizontalAccuracy:0
                                           verticalAccuracy:0
                                                  timestamp:[NSDate date]] autorelease];

答案 1 :(得分:1)

CLLocation个对象是不可变的(你不能改变它们)。根据文件:

  

通常,您使用CLLocationManager对象根据用户设备的最后已知位置创建此类的实例。但是,如果要缓存自定义位置数据或获取两个不同坐标点之间的距离,则可以自己创建实例。