gpt4 book ai didi

ios - 无法使用类型为 '^' 的参数列表调用 '($T27, IntegerLiteralConvertible)'

转载 作者:行者123 更新时间:2023-11-28 10:24:38 28 4
gpt4 key购买 nike

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))

There is an Error in Line in Variable "a". said 'Cannot Invoke '^' with an argument list of type '($T27, IntegerLiteralConvertible)'.

最佳答案

我猜您想使用 pow(x,y) 函数返回 x 的 y 次方。

所以为了访问这个函数你需要先导入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
}

关于ios - 无法使用类型为 '^' 的参数列表调用 '($T27, IntegerLiteralConvertible)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29331305/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com