iPhone MKMapView Annotation Clustering

You don’t necessarily need to use a 3rd party framework because since iOS 4.2, MKMapView has a method called – (NSSet *)annotationsInMapRect:(MKMapRect)mapRect which you can use to do your clustering. Check out the WWDC11 Session video ‘Visualizing Information Geographically with MapKit‘. About half way through it explains how to do it. But I’ll summarize the … Read more

Snapshot of MKMapView in iOS7

You can use MKMapSnapshotter and grab the image from the resulting MKMapSnapshot. See the discussion of it WWDC 2013 session video, Putting Map Kit in Perspective. For example: MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region = self.mapView.region; options.scale = [UIScreen mainScreen].scale; options.size = self.mapView.frame.size; MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options]; [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) … Read more

Is there a way to add text using Paths Drawing

With MKOverlayPathView, I think the easiest way to add text is to override drawMapRect:zoomScale:inContext: and put the path and text drawing there (and do nothing in or don’t implement createPath). But if you’re going to use drawMapRect anyway, you might want to just switch to subclassing a plain MKOverlayView instead of MKOverlayPathView. With an MKOverlayView, … Read more

Calculating tiles to display in a MapRect when “over-zoomed” beyond the overlay tile set

Imagine that the overlay is cloud cover – or in our case, cellular signal coverage. It might not “look good” while zoomed in deep, but the overlay is still conveying essential information to the user. I’ve worked around the problem by adding an OverZoom mode to enhance Apple’s TileMap sample code. Here is the new … Read more

how to manage drag and drop for MKAnnotationView on IOS?

If you’ve setup your MKAnnotation object with a setCoordinate method properly, then in the didChangeDragState method, the new coordinate should already be in the annotation object: – (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateEnding) { CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate; NSLog(@”dropped at %f,%f”, droppedAt.latitude, droppedAt.longitude); } } For reference, see the “Marking … Read more

How do I create an image overlay and add to MKMapView?

Here is an example to how to sets a UIImage to a MKMapView overlay. Some parameter (coordinates and image path) are fixed, but the code can be easily changed, I guess. Create an class that conforms to MKOverlay: MapOverlay.h @interface MapOverlay : NSObject <MKOverlay> { } – (MKMapRect)boundingMapRect; @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @end MapOverlay.m … Read more

How to get click event from a button added over MKAnnotationView

The standard UI approach is to use the callout view and add an accessory button as progrmr shows. However, if you must add a button directly to the MKAnnotationView, the problems with your approach are that the MKPinAnnotationView‘s default frame (which can’t easily be changed) is smaller than the button you’re adding so most of … Read more