Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing color as location updates without removing annotation from map? #22

Open
billardkarr opened this issue Jul 14, 2016 · 0 comments

Comments

@billardkarr
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant