MKPolygon area calculation

The whole algorithm implemented in Swift 3.0 : import MapKit let kEarthRadius = 6378137.0 // CLLocationCoordinate2D uses degrees but we need radians func radians(degrees: Double) -> Double { return degrees * M_PI / 180; } func regionArea(locations: [CLLocationCoordinate2D]) -> Double { guard locations.count > 2 else { return 0 } var area = 0.0 for … Read more

Custom MKPinAnnotation callout bubble similar to default callout bubble

I have developed a custom callout bubble that is nearly identical to the system callout bubble, but gives more flexibility over the height and content. It should be fairly trivial to adjust the appearance to suit your needs. See my post on the Asynchrony Solutions blog for example code and the steps required to implement … Read more

iOS – How to limit the MapView to a specific region?

After trying different ways of limited MKMapView I’ve concluded that using mapDidChange, and resetting if you’re center point goes outside of the boundaries works best, with animated: YES Here’s how I do it (Using the New Zealand lat/Long span/center). – (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ if ((mapView.region.span.latitudeDelta > 15.589921 ) || (mapView.region.span.longitudeDelta > 175.836914) ) { CLLocationCoordinate2D … Read more

How to define the order of overlapping MKAnnotationViews?

Ok, so for solution use method from MKMapViewDelegate – (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views In this method you should rearrange AnnotationView after it was added to mapKit View. So, code may looks like this: – (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { for (MKAnnotationView * annView in views) { TopBottomAnnotation * ann = (TopBottomAnnotation *) [annView annotation]; if … Read more

Customize MKAnnotation Callout View?

It should first be noted that the simplest changes to the callout are enabled by simply adjusting the properties of the system provided callout, but customizing the right and left accessories (via rightCalloutAccessoryView and leftCalloutAccessoryView). You can do that configuration in viewForAnnotation. Since iOS 9, we have access to the detailCalloutAccessoryView which, replaces the subtitle … Read more

Finding Path/Route Between two points on MapKit in iPhone

Below is the code to finds path & draws line between two locations. To implement below class: _mapRecord = [[PSMapDirection alloc] initWithFrame:CGRectMake(0.0, 49.0, 320.0, 411.0)]; [self.view addSubview:_mapRecord]; MapDirection.h #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import “RegexKitLite.h” @interface MapDirection : UIView<MKMapViewDelegate> { MKMapView* mapView; NSArray* routes; BOOL isUpdatingRoutes; } -(void) showRouteFrom: (MKAnnotation*) f to:(MKAnnotation*) t; @end MapDirection.m #import … Read more

MKMapView Zoom and Region

First of all, MKMapView does not use/have a predefined set of zoom levels like Google Maps does. Instead, the visible area of a MKMapView is described using MKCoordinateRegion, which consists of two values: center (the center point of the region), and span (the size of the visible area around center). The center point should be … Read more

Custom MKAnnotation callout bubble with button

There are several approaches to customizing callouts: The easiest approach is to use the existing right and left callout accessories, and put your button in one of those. For example: – (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { static NSString *identifier = @”MyAnnotationView”; if ([annotation isKindOfClass:[MKUserLocation class]]) { return nil; } MKPinAnnotationView *view = (id)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if … Read more