Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Convert MKMapRect to CLRegion aka convert visible region of mapview to CLRegion
- (CLLocationDistance)getDistanceFrom:(CLLocationCoordinate2D)start to:(CLLocationCoordinate2D)end
CLLocation *startLoc = [[CLLocation alloc] initWithLatitude:start.latitude longitude:start.longitude];
CLLocation *endLoc = [[CLLocation alloc] initWithLatitude:end.latitude longitude:end.longitude];
CLLocationDistance retVal = [startLoc distanceFromLocation:endLoc];
[startLoc release];
[endLoc release];
return retVal;
- (void) convert
MKMapRect mRect = self.mapview.visibleMapRect;
MKMapPoint neMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), mRect.origin.y);
MKMapPoint swMapPoint = MKMapPointMake(mRect.origin.x, MKMapRectGetMaxY(mRect));
CLLocationCoordinate2D neCoord = MKCoordinateForMapPoint(neMapPoint);
CLLocationCoordinate2D swCoord = MKCoordinateForMapPoint(swMapPoint);
CLLocationDistance diameter = [self getDistanceFrom:neCoord to:swCoord];
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter: mapview_.centerCoordinate radius:(diameter/2) identifier:@"mapWindow"];
//Now we can geocode an address inside the map's visible view...
//CLGeocoder *geocoder = [[CLGeocoder alloc] init];
//[geocoder geocodeAddressString:theSearchBar.text inRegion:region completionHandler:^(NSArray *placemarks, NSError *error) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.