-
Notifications
You must be signed in to change notification settings - Fork 115
Description
I love this annotation, but I have a question!
I'm using it in a map based app I'm working on in Swift (I just started developing in Xcode a couple months ago, so I'm unfamiliar with Objective-C), but I want the color of the annotation on the map to change according to speed of a user as the location changes without removing the annotation from the map. The UserLocation pulsing annotation does this if you change the TintColor of the map.
In my code, I'm updating the annotation color as follows. I have a class I created called vehicle where I can access updates to location, etc. of vehicles (these vehicles are not necessarily the user, their info is stored in a database we're accessing). I also created a custom annotation called MGAnnotation that has a property called color that I can change dynamically and vehicle.icon is an instance of it. Finally, I have a function updateColor() which calculates a color using the speed.
vehicle.icon.subtitle = "Speed: \(speed) m/s"
vehicle.icon.color = updateColor(speed)
vehicle.icon.coordinate = last_location
mapView.addAnnotation(vehicle.icon)
In the rendering function I have:
if let annotation = annotation as? MGAnnotation {
let annotationView = SVPulsingAnnotationView(annotation: annotation, reuseIdentifier: "pulse")
annotationView.annotationColor = annotation.color
annotationView.canShowCallout = true
return annotationView
}
In the first block of code, when vehicle.icon.coordinate changes, the annotation changes location on the map accordingly, but the color doesn't update. Is there any easy fix to this that I could make in the SVPulsingAnnotation code?
Thanks!