2014-10-09 56 views
-1

我需要只用坐标的CLLocation阵列,像这样:CLLocation只得到坐标

var locations = [CLLocation(latitude: 38.5, longitude: -120.2), 
     CLLocation(latitude: 40.7000, longitude: -120.95000), 
     CLLocation(latitude: 43.25200, longitude: -126.453000)] 

我目前保存的每个位置,像这样:

var locationArray: [CLLocation] = [] 

在didUpdateLocations:

locationArray.append(locations[0] as CLLocation) 

但我总是得到的是这样的:

[< -122.02684687,+ 37.32956209> +/-0.00米(-1.00速度MPS /当然-1.00)@ 14年10月9日,下午2时十二分49秒欧洲中部夏令时间,< -122.02685248, +37.32959580> +/- 0.00m(速度-1.00 mps/course -1.00)@ 10/9/14,2:12:49 PM中欧夏令时,< -122.02685221,+ 37.32963096> +/- 0.00m(速度-1.00 mps/course -1.00)@ 10/9/14,2:12:49 PM中欧夏令时,< -122.02685460,+ 37.32966692> +/- 0.00m(速度-1.00 mps/course -1.00)@ 10/9/14,2:12:49 PM中欧夏令时

我试着将它转换成CLLocationCoordinate2D,但我总是得到满的位置数组,从来没有上面的例子。我也试过这样的事情:

for (index,element) in enumerate(locationArray) { 

     var cllocation = CLLocation(latitude: element.coordinate.longitude, longitude: element.coordinate.latitude) 

     coordinatesArray.append(cllocation) 

    } 

但是,这也返回完整的位置数组。我做错了什么?我如何创建一个只有坐标的CLLocation数组?如果你能指出我的方向太棒了,那就太棒了。

回答

1

如何:

var locationArray: [CLLocationCoordinate2D] = [] 
locationArray.append(CLLocationCoordinate2D(latitude: ..., longitude: ...)) 

CLLocation包含所有其他东西一样coursealtitude,精度...

CLLocationCoordinate2D只包含经度和纬度。