CLLocation的改变坐标(Changing coordinates of CLLocation

2019-09-21 13:07发布

我新的目标C,所以这可能是一个小问题:

初始化位置后:

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

我怎么可以改变的纬度和经度以后呢?

Answer 1:

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

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



Answer 2:

这里有一个如何修改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];


文章来源: Changing coordinates of CLLocation
标签: cocoa-touch