【发布时间】:2015-04-03 12:01:34
【问题描述】:
我想计算 Swift 中两个位置之间的方位角。我尝试了一些代码,但它不起作用。我搜索了这个问题,但没有找到任何结果。
func calculat(userlocation:CLLocation){
let latuserlocation: () = DegreesToRadians(userlocation.coordinate.latitude)
let lonuserlocatioc: () = DegreesToRadians(userlocation.coordinate.longitude)
latitude = NSString (string: places[activePlace]["lat"]!).doubleValue
longitude = NSString (string: places[activePlace]["lon"]!).doubleValue
let targetedPointLatitude: () = DegreesToRadians(latitude)
let targetedPointlongitude: () = DegreesToRadians(longitude)
let dlon = lonuserlocatioc - targetedPointlongitude
let y = sin(dLon) * cos(targetedPointLatitude);
let x = cos(latuserlocation) * sin(targetedPointLatitude) - sin(latuserlocation) * cos(targetedPointLatitude) * cos(dLon);
let radiansBearing = atan2(y, x);
return RadiansToDegrees(radiansBearing)
let dlon = lonuserlocatioc - targetedPointlongitude 的错误是:
(不能使用类型为“((),())”的参数列表调用“-”)
【问题讨论】:
-
我尝试了这个但不起作用(在 Swift [重复] 中计算两个 CLLocation 点之间的方位)
-
代码没有意义。有一个 return 语句,但 func 没有说它会返回一个值。为什么要将纬度和经度变量声明为元组,然后尝试对它们进行算术(减法)?与其说“不工作”,不如说确切的错误或问题是什么,因为有无数种方法可能会“不工作”。
标签: swift cllocation