我正在尝试对CLLocationCoordinate2DMake
进行编码以将其更改为array
,因此纬度和经度会根据indxPath
而改变...
就像我在这里尝试的那样:
var Longitude = ["32.101145","32.074961","",""]
var Latitude = ["34.775163","34.781679","","",""]
//What i tried :
let LightHouseLocation = CLLocationCoordinate2DMake(Longitude[indexPath.row],Latitude[indexPath.row])
// Drop a pin
但是当然它给我丢了错误。如果有人可以帮助我,我将不胜感激,谢谢。
最佳答案
这就是我要做的。
class ViewController: UIViewController {
@IBOutlet weak var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var coordinates = Array<CLLocationCoordinate2D>()
coordinates.append(CLLocationCoordinate2DMake(32.101145, 32.074961))
coordinates.append(CLLocationCoordinate2DMake(34.775163, 34.781679))
let pins = coordinates.map { (coordinate) -> MKPointAnnotation in
let pin = MKPointAnnotation()
pin.coordinate = coordinate
return pin
}
self.map.addAnnotations(pins)
}
}
关于ios - 通过indexPath更改CLLocationCoordinate2DMake与数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44221041/