通过 indexPath 更改 CLLocationCoordinate2DMake 与数组
Change CLLocationCoordinate2DMake With array by indexPath
我正在尝试对 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)
}
}
我正在尝试对 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)
}
}