Update
Version 3.2 with new sample for iOS 4.2 is available here.
I spent almost one week to rewrite my previous MapKit sample with cool CoreAnimation effects on those little pins that just work like Maps.app on iPhone. The animation part is very similar to current MapKit’s private API design: using class methods to generate animations and apply to annotation view when touch events fired.
Features
- Draggable pin with CoreAnimation effects in the MapView
- Use CLLocationManager to find current position
- Use MKReverseGeocoder to lookup address
Design
- DDAnnotation is thin, just subclass from MKPlacemark, which also confirms to MKAnnotation protocol.
- DDAnnotation can be init’d with existing address info, so you won’t need to reverse geocoding when creating the annotation.
- DDAnnotation re-declared MKAnnotation’s readonly property ‘coordinate’ to readwrite-able. So you can update the coordinate after created.
- DDAnnotationView is subclassing from MKAnnotationView now, and using several pin images from MapKit.framework.
- To enable drag-and-drop, you must assign MKMapView instace to DDAnnotationView.
- DDAnnotationView now comes with CoreAnimation effects, including:
- Pin bounce when touched.
- Pin bounce and left for dragging.
- Pin drop and bounce when releasing the touch without moving.
- Pin lift, drop and bounce when releasing the touch after moving to the new position.
Issues
If you do reverse geocoding too many times within a very short of period, you might get error from Apple/Google (so don’t do this in your real world apps):
/SourceCache/ProtocolBuffer/ProtocolBuffer-19/Runtime/PBRequester.m:446 server returned error: 503
Pin animations are almost perfect, but still need some works, I will kept things updated if possible.
Where to download
The source code is available on github.
Reference
MapKit annotation drag and drop with callout info update