我尝试将CLLocationCoordinate2DMake
编码为array
进行更改,因此lat和long将根据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
但当然它给我带来了错误。如果有人能帮助我,我将不胜感激,谢谢。
答案 0 :(得分:0)
我就是这样做的。
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)
}
}