我需要获得一个只有坐标的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)
但我总是得到的是这样的:
并[d -122.02684687,+ 37.32956209> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 10/9/14,中欧时间夏季时间2:12:49,< -122.02685248,+ 37.32959580> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 10/9/14,中欧时间夏令时2:12:49,< -122.02685221,+ 37.32963096> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 10/9/14,中欧时间夏令时间2:12:49,< -122.02685460,+ 37.32966692> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 10/9/14,中欧夏令时间下午2:12:49
我尝试将其转换为CLLocationCoordinate2D,但我总是得到完整的位置数组,而不是上面的例子。我也试过这样的事情:
for (index,element) in enumerate(locationArray) {
var cllocation = CLLocation(latitude: element.coordinate.longitude, longitude: element.coordinate.latitude)
coordinatesArray.append(cllocation)
}
但是这也会返回完整的位置数组。我做错了什么?如何创建仅包含坐标的CLLocation数组?如果你能指出我正确的方向,这将是太棒了。
答案 0 :(得分:1)
怎么样:
var locationArray: [CLLocationCoordinate2D] = []
locationArray.append(CLLocationCoordinate2D(latitude: ..., longitude: ...))
CLLocation
包含所有其他内容,例如course
,altitude
,准确性......
CLLocationCoordinate2D
只包含纬度和经度。
答案 1 :(得分:0)
您可以迭代抛出CLLocationCoordinate2D数组并将其转换为CLLocation。 CLLocation有一个合适的init方法(- (instancetype)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude。