1

我想用绿色表示从查询到 Parse 的所有用户坐标,但我想要红色的用户(当前)之一。

以下是我到目前为止所拥有的

import UIKit
import MapKit

class MultipleAnnotationViewController: UIViewController, MKMapViewDelegate
{
    var arrayOfPFObject: [PFObject] = [PFObject]()
    var lat_ :Double = 0
    var long_ :Double = 0
    @IBOutlet weak var dispAnnotation: MKMapView!
    let currentUser = PFUser.currentUser()
    override func viewDidLoad()
    {
        super.viewDidLoad()
        dispAnnotation.delegate = self
        for coordinateItem in arrayOfPFObject
        {
            let pointAnnotation = MKPointAnnotation()
            self.lat_ = coordinateItem["Latitude"] as! Double
            self.long_ = coordinateItem["Longitude"] as! Double
            pointAnnotation.coordinate = CLLocationCoordinate2D(latitude:  self.lat_, longitude: self.long_)
            dispAnnotation.addAnnotation(pointAnnotation)
        }
    }
    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
    {
        guard !(annotation is MKUserLocation)
            else
        { return nil }
        let identifier = "com.domain.app.something"
        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? MKPinAnnotationView
        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.pinTintColor = UIColor.greenColor()
            annotationView?.canShowCallout = true
        } else {
            annotationView?.annotation = annotation
        }
        return annotationView
    }
}

目前,如果arrayOfPFObject运行四次,我会得到四个绿色的注释图钉,但我希望其中一个(当前用户)为红色。我将电子邮件 ID 存储为对所有用户都是唯一的,因此我可以使用它来区分当前用户和其余用户

  1. 所以我想在我的 mapView 方法中写这样的东西,但是 mapView 不会将坐标项数组识别为它不在他的范围内:

    if(String(coordinateItem["email"]) == String((currentUser?.valueForKey("email"))!))

    {

        annotationView?.pinTintColor = UIColor.redColor()
    
        }
        else
        {
        annotationView?.pinTintColor = UIColor.greenColor()
        }
    
  2. 我认为这种方法行不通,然后在不同的注释上我可以在查询结果中禁止当前用户,并添加一个查询作为

query.whereKey("objectId", notEqualTo: (currentUser?.valueForKey("objectId"))!)

现在我的循环arraOfPFObject将运行三次,我将得到三个绿色注释。但是现在再次回到主要问题,即如何绘制第四个,这意味着当前用户是红色的。我可以轻松捕获第四个位置坐标,但现在如何用红色绘制它们。如果我需要更清楚地了解我想要实现的目标,请告诉我。

4

0 回答 0