gpt4 book ai didi

arrays - Swift 为值数组绘制路线

转载 作者:搜寻专家 更新时间:2023-11-01 05:34:29 25 4
gpt4 key购买 nike

您好,我有一个像这样的数组 route = [[latitude,longitude],[latitude,longitude]...]。我应该画一条遵循数组坐标的线。我试过这个功能:

 func addPolylineToMap(locations: [CLLocation]){
var coordinates = locations.map({ (location: CLLocation!) -> CLLocationCoordinate2D in
return location.coordinate})
var countLocations = locations.count
let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count: locations.count)
mapView.addOverlay(geodesic)
}

并调用给它数组路由的函数:

addPolylineToMap(locations: route as! [CLLocation])

但是编译器给我错误ambiguous use of 'init(coordinates:count:)'

无论如何,我不太确定它是否可行。有人可以向我解释如何做得更好吗?

附言

路线

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

let userLocation: CLLocation = locations[0] as CLLocation

manager.startUpdatingLocation()
var userLatitude = (userLocation.coordinate.latitude)
var userLongitude = (userLocation.coordinate.longitude)
userMoves = [(userLatitude),(userLongitude)]

route 是一个附加用户移动的数组

最佳答案

您可以删除那个&。在 Swift 3 中:

func addPolylineToMap(locations: [CLLocation]) {
let coordinates = locations.map { $0.coordinate }
let geodesic = MKGeodesicPolyline(coordinates: coordinates, count: coordinates.count)
mapView.add(geodesic)
}

或者在 Swift 2 中:

func addPolylineToMap(locations: [CLLocation]) {
let coordinates = locations.map { $0.coordinate }
let geodesic = MKGeodesicPolyline(coordinates: coordinates, count: coordinates.count)
mapView.addOverlay(geodesic)
}

关于arrays - Swift 为值数组绘制路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44079663/

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