Skip to content

Instantly share code, notes, and snippets.

@joeldrotleff
Created November 19, 2013 21:54
Show Gist options
  • Save joeldrotleff/7553256 to your computer and use it in GitHub Desktop.
Save joeldrotleff/7553256 to your computer and use it in GitHub Desktop.
Objective-C category to get the radius of an MKMapView
//
// Created by Joel Drotleff on 11/19/13.
// Copyright (c) 2013 Joel Drotleff. All rights reserved.
//
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MKMapView+Utilities.h"
@implementation MKMapView (Utilities)
- (CLLocationDistance)getRadius
{
// init center location from center coordinate
CLLocation *centerLocation = [[CLLocation alloc] initWithLatitude:self.centerCoordinate.latitude
longitude:self.centerCoordinate.longitude];
double topCenterLat = centerLocation.coordinate.latitude-self.region.span.latitudeDelta/2.;
CLLocation *topCenterLocation = [[CLLocation alloc] initWithLatitude:topCenterLat
longitude:centerLocation.coordinate.longitude];
CLLocationDistance distance = [centerLocation distanceFromLocation:topCenterLocation];
return distance;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment