我正在尝试显示带有json服务器坐标的标记。
我使用这个代码来获得坐标:
let query = PFQuery(className:"locations")
query.findObjectsInBackgroundWithBlock {
(objects:[PFObject]?, error:NSError?) -> Void in
if error == nil {
for object in objects! {
self.long = object["longitude"] as! Double
self.lat = object["latitude"] as! Double
print(self.lat, self.long)
}
} else {
print(error)
}
}我从print(self.lat,self.long)得到了这个结果
39.570355 2.679148
39.570364 2.687386
39.569988 2.691598
39.569756 2.695900我用这个在地图上显示出来:
marker.position = CLLocationCoordinate2DMake(self.lat, self.long)现在,我想循环这个结果,首先显示第一行与地图上的坐标,当我点击一个按钮时,我希望它显示下一行。这在某种程度上有可能吗?我不知道该怎么做。
发布于 2015-12-03 08:09:20
首先,您应该创建两个数组,一个用于纬度,另一个用于经度。从示例中获取的纬度和经度值
var latitudeArr : NSMutableArray = NSMutableArray()
var longitudeArr : NSMutableArray = NSMutableArray()
let lat1 : Double = 63.82869
let lat2 : Double = 63.828743
let lat3 : Double = 63.828528
let lat4 : Double = 63.82862
latitudeArr = NSMutableArray(array: [lat1,lat2,lat3,lat4])
let long1 : Double = 20.263622
let long2 : Double = 20.264524
let long3 : Double = 20.263274
let long4 : Double = 20.264034
longitudeArr = NSMutableArray(array: [long1,long2,long3,long4])现在您必须运行一个循环来在mapView上设置一个概念
for index in 0...3 {
let annotation: MKPointAnnotation = MKPointAnnotation()
annotation.title = "name"
let latitude: Double = latitudeArr.objectAtIndex(index) as! Double
let longitude: Double = longitudeArr.objectAtIndex(index) as! Double
annotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude)
self.mapView.addAnnotation(annotation)
}它肯定会对你有用的
https://stackoverflow.com/questions/34060091
复制相似问题