1

I want to denote all the user coordinate which are coming from query to Parse in green color but I want the one of the user (current) in red color.

Below is what I have till now

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
    }
}

Currently If the arrayOfPFObject runs four times I get four annotation pins in green color but I want one of them (current User) to be of red color. I am storing email id as unique to all user so I can use that to distinguish between current and rest of the user

  1. So I want something like this to be written in my mapView method, but mapView will not recognize the coordinateItem array as its not in his scope :

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

    {

        annotationView?.pinTintColor = UIColor.redColor()
    
        }
        else
        {
        annotationView?.pinTintColor = UIColor.greenColor()
        }
    
  2. I think this approach will not work then on a different note I can bar the current user in my query result with addition of one query as

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

Now my loop of arraOfPFObject will run three times and I will get three green annotation. But now again back to main question that how to draw the fourth one which means the current user to be of red color. I can capture easily the fourth location coordinate but now how to draw them in red color. Please let me know If I need to be more clear on what I want to achieve.

Unbreakable
  • 7,776
  • 24
  • 90
  • 171

0 Answers0