无法使用类型’($ T27,IntegerLiteralConvertible)’的参数列表调用’^’

func FindDistance(currentLatitude: Double, currentLongtitude: Double, compareLatitude: Double, compareLongtitdue: Double) -> Double { var dlon = compareLongtitdue - currentLongtitude var dlat = compareLatitude - currentLatitude let WorldRadius = 6371 var a = sin(dlat/2)^2 + cos(currentLatitude) * cos(compareLatitude) * sin(dlon/2)^2 var c = 2 * atan2(sqrt(a), sqrt(1-a)) var d = WorldRadius * c } 

println(FindDistance(11.583431, 104.920141, 11.584966, 104.918569))

变量“a”中的行中存在错误。 用’($ T27,IntegerLiteralConvertible)’类型的参数列表说’无法调用’^’。

我想你想使用pow(x,y)函数,它将x提升到y的幂。

因此,要访问此function,您需要先导入Darwin并重写代码,如下所示:

 import Darwin func FindDistance(currentLatitude:Double, currentLongtitude:Double, compareLatitude:Double, compareLongtitdue:Double) -> Double { var dlon = compareLongtitdue - currentLongtitude var dlat = compareLatitude - currentLatitude let WorldRadius: Double = 6371 var a = pow(sin(dlat/2), 2) + cos(currentLatitude) * cos(compareLatitude) * pow(sin(dlon/2),2) var c = 2 * atan2( sqrt(a), sqrt(1-a) ) var d = WorldRadius * c return d }