更改CLLocation的坐标

4

我是Objective-C的新手,所以这可能是一个简单的问题:

在初始化位置之后:

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

如何在之后更改纬度和经度?
2个回答

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

CLLocation 对象是不可变的(您无法更改它们)。根据文档:

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


谢谢,那我将使用变量来存储位置并使其可更改。 - Mike

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接