ios - 通过解析将时间戳添加到 MapView 注释?

标签 ios xcode swift time parse-platform

这是我当前的查询设置,用于从解析中检索数据并将其设置到 mapView 上的注释引脚。我还想花时间创建并在注释中添加一个简单的 5:00PM 例如。有没有办法通过我的查询从解析中提取时间而不是日期并将其设置为 MKAnnotation

override func viewDidAppear(animated: Bool) {
var annotationQuery = PFQuery(className: "Post")
currentLoc = PFGeoPoint(location: MapViewLocationManager.location)
//annotationQuery.whereKey("Location", nearGeoPoint: currentLoc, withinMiles: 10)
annotationQuery.whereKeyExists("Location")
annotationQuery.findObjectsInBackgroundWithBlock {
    (points, error) -> Void in
    if error == nil {
        // The find succeeded.
        println("Successful query for annotations")
        // Do something with the found objects

        let myPosts = points as! [PFObject]

        for post in myPosts {
            let point = post["Location"] as! PFGeoPoint
            let annotation = MKPointAnnotation()
            annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
            annotation.title = post["title"] as! String!
            annotation.subtitle = post["username"] as! String!


            self.mapView.addAnnotation(annotation)
        }

    } else {
        // Log details of the failure
        println("Error: \(error)")
    }
}

这是我的 Parse 后端的照片,可以让您更好地了解:

http://i1249.photobucket.com/albums/hh512/zachkhan3/Screen%20Shot%202015-04-24%20at%205.39.18%20PM.png

最佳答案

PFObject 有一个“CreatedAt”属性。您将其分配给 NSDate 对象,并且需要使用 NSDateFormatter 对其进行格式化以仅显示时间部分。未经测试的代码。

       for post in myPosts {
        let point = post["Location"] as! PFGeoPoint
        let annotation = MKPointAnnotation()
        annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
        annotation.title = post["title"] as! String!
        annotation.subtitle = post["username"] as! String!
        let formatter = NSDateFormatter()
        formatter.dateStyle = NSDateFormatterStyle.NoStyle
        formatter.timeStyle = .ShortStyle

        let dateString = formatter.stringFromDate(post.createdAt)
        annotation.timeTitle /* or something equivalent */ = dateString

        self.mapView.addAnnotation(annotation)
    }

关于ios - 通过解析将时间戳添加到 MapView 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29860317/

相关文章:

ios - 快速初始化 UITextField 的子类

ios - 应用程序在 iPad 上运行,而其 iPhone-Only

iphone - 应用程序图标未在 iPhone 模拟器中显示

ios - 调度组通知似乎被调用得太早

arrays - 如何检查任何类型的变量是否为数组

ios - 当我设置动画(使用我的自定义动画)scrollToItem 函数时,UICollectionView 单元格消失

iOS CGContextAddArc 和不同的屏幕分辨率

ios - Facebook SDK ios v4.4.0 didFinishLaunchingWithOptions

ios - 确认命令未找到错误

swift - NSDate timeIntervalSince1970 无法在 Swift 中工作?