Swift 5 Track CLLocation当前位置点

时间:2019-05-31 09:50:56

标签: swift location cllocationmanager gmsmapview

我想在当前位置点周围画一个圆,并用该点移动它。我做了GMSCircle,并设置了从 didUpdateLocations 获得的newCoordinates。但是 didUpdateLocations 中的“点坐标”和实际坐标是不同的(请看截图)

GMSCircle

lazy var circle: GMSCircle = {
    let circle = GMSCircle()

    circle.fillColor = PineappleColors.green.color.withAlphaComponent(0.2)
    circle.strokeWidth = 0
    circle.strokeColor = PineappleColors.green.color

    return circle
}()

设置圈子

func setCircle(_ loc: CLLocationCoordinate2D){
    UI.circle.position = loc
    UI.circle.map = UI.map
}

didUpdateLocations

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    guard let location = locations.first else {
        return
    }
    let newLoc: CLLocationCoordinate2D = (manager.location?.coordinate)!
    UI.map.clear()
    setCircle(newLoc)
    disableLocationManager()
}

enter image description here

0 个答案:

没有答案