快速错误:无法分配给属性:“坐标”是不可变的

问题描述 投票:0回答:2

我需要你的帮助。问题是当我编写此行代码尝试将用户位置转换为另一个坐标时,出现此错误:无法分配给属性:“坐标”是不可变的

代码为:

var location = sender.location(in: self.mapView)
let locCoord = self.mapView.convert(location, toCoordinateFrom: self.mapView)
self.mapView.userLocation.coordinate = locCoord   *// Cannot assign to property:'coordinate' is immutable*

您能帮忙吗?

swift xcode mapkit
2个回答
1
投票

由于错误表明coordibate属性是不可变的

var coordinate: CLLocationCoordinate2D { get }
var userLocation: CLLocation { get }

除了userLocation之外,您无法更改它,如果需要其他位置,请直接与


0
投票

coordinate是仅获取的属性,表示您无法将其设置为任何内容。使用mapView的方法来设置当前坐标。

© www.soinside.com 2019 - 2024. All rights reserved.