从 MKMapView 上的 CLLocationCoordinate2D 数组添加点不起作用
adding points from a CLLocationCoordinate2D array on MKMapView doesn't work
我正在使用以下代码在单击按钮时将存储的针点添加到 myMKMap ;
func addPoint(){
var count: Int = 0
repeat {
let pin = MKPointAnnotation()
pin.coordinate = CLLocationCoordinate2D(mypointList[count])
pin.title = placenames[count]
pin.subtitle = placedetails[count]
mymap.addAnnotation(pin)
count += 1
}
while count < 3
mypointList[] 如下所示;
var mypointList = [CLLocationCoordinate2D(latitude: 37.19722, longitude: 25.82189),
CLLocationCoordinate2D(latitude: 37.20103, longitude: 25.83009),
CLLocationCoordinate2D(latitude: 37.20092, longitude: 25.81781),
CLLocationCoordinate2D(latitude: 37.19989, longitude: 2259.82449)]
var placenames: [String] = ["sample place 1", "sample place 2", "sample place 3", "sample place 4"]
var placedetails: [String] = ["sample place detail 1", "sample place detail 2", "sample place detail 3", "sample place detail 4"]
但是当我运行应用程序时没有添加引脚。
顺便说一句,以下代码在重复循环中替换为“pin.coordinate = CLLocationCoordinate2D(mypointList[count])”行时有效;
pin.coordinate = CLLocationCoordinate2D(latitude: 37.1972, longitude: 25.2744)
数组有问题吗?
谢谢
不过这听起来有点奇怪,我已经通过替换以下代码解决了我的问题:
pin.coordinate = CLLocationCoordinate2D(latitude: mypointList[count].latitude as! CLLocationDegrees, longitude: mypointList[count].longitude as! CLLocationDegrees)
现在可以正确显示引脚了。
我正在使用以下代码在单击按钮时将存储的针点添加到 myMKMap ;
func addPoint(){
var count: Int = 0
repeat {
let pin = MKPointAnnotation()
pin.coordinate = CLLocationCoordinate2D(mypointList[count])
pin.title = placenames[count]
pin.subtitle = placedetails[count]
mymap.addAnnotation(pin)
count += 1
}
while count < 3
mypointList[] 如下所示;
var mypointList = [CLLocationCoordinate2D(latitude: 37.19722, longitude: 25.82189),
CLLocationCoordinate2D(latitude: 37.20103, longitude: 25.83009),
CLLocationCoordinate2D(latitude: 37.20092, longitude: 25.81781),
CLLocationCoordinate2D(latitude: 37.19989, longitude: 2259.82449)]
var placenames: [String] = ["sample place 1", "sample place 2", "sample place 3", "sample place 4"]
var placedetails: [String] = ["sample place detail 1", "sample place detail 2", "sample place detail 3", "sample place detail 4"]
但是当我运行应用程序时没有添加引脚。
顺便说一句,以下代码在重复循环中替换为“pin.coordinate = CLLocationCoordinate2D(mypointList[count])”行时有效;
pin.coordinate = CLLocationCoordinate2D(latitude: 37.1972, longitude: 25.2744)
数组有问题吗?
谢谢
不过这听起来有点奇怪,我已经通过替换以下代码解决了我的问题:
pin.coordinate = CLLocationCoordinate2D(latitude: mypointList[count].latitude as! CLLocationDegrees, longitude: mypointList[count].longitude as! CLLocationDegrees)
现在可以正确显示引脚了。