title: MapKit (iOS) -- Live MKAnnotation Motion
body: <p>I'm designing an app using Swift for a food truck. I want to use MapKit to show a pin on the live location of the truck so one can look at the app to see it moving in realtime. I was able to get the server-side element set up using PHP/MySQL. Currently, the app makes a HTTP request every 3 seconds.</p>
  
  <p>How should I go about animating the moving pin (or other image)? I tried a few methods already (if you have others, please suggest!):</p>
  
  <ol>
  <li>I removed the pin and quickly added a new one in my HTTP function. While this works, I would prefer a smooth animation, not a flashing, jerky pin.</li>
  <li>I subclassed <code>MKMapViewDelgate</code> like with a <code>didAddAnnotationViews</code> delegate that animates the pin's frame using <code>UIView.animateWithDuration</code> <a href="https://stackoverflow.com/questions/2655465/custom-pin-animation-mkmapview">as suggested here</a>. Animation only occurred when the map was initially loaded. Also, I have no idea how this would work with coordinates, since it involves frames.</li>
  <li><p>I subclassed <code>MKAnnotation</code> with a modifiable <code>var coordinate</code>. In my HTTP function, I changed the coordinate. <strong>EDIT</strong>: This now works since I <a href="https://stackoverflow.com/a/1205230/4967340">properly refreshed</a> the mapView (thanks @Paulw11). However, I still have two main issues:</p>
  
  <ul>
  <li>There's no linear animation, which I desire to better simulate real-time movement. How would I go about animating the pin's coordinates? Should I use UIView, like in method 2, a fast NSTimer, or something else?</li>
  <li>Due to using the <code>setCenterCoordinate</code> function to forcibly refresh the map, the map cancels any current touches. How do I detect if there's any touches on the MapView so I can prevent the forced update?</li>
  </ul></li>
  </ol>