2014-10-09 55 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只包含經度和緯度。