Skip to content

Instantly share code, notes, and snippets.

@zssz
Created November 26, 2010 21:22
Show Gist options
  • Save zssz/717230 to your computer and use it in GitHub Desktop.
Save zssz/717230 to your computer and use it in GitHub Desktop.
Scrolls the map the point amount specified in offset and optionally animates this.
- (void)scrollWithOffset:(CGSize)offset animated:(BOOL)animated
{
MKMapPoint centerMapPoint = MKMapPointForCoordinate(self.centerCoordinate);
CGPoint centerPoint = [self convertCoordinate:self.centerCoordinate toPointToView:self];
CGPoint destinationPoint = CGPointMake(centerPoint.x+offset.width, centerPoint.y+offset.height);
CLLocationCoordinate2D destinationCoordinate = [self convertPoint:destinationPoint toCoordinateFromView:self];
MKMapPoint destMapPoint = MKMapPointForCoordinate(destinationCoordinate);
MKMapRect mapRect = self.visibleMapRect;
mapRect = MKMapRectOffset(mapRect, centerMapPoint.x-destMapPoint.x, centerMapPoint.y-destMapPoint.y);
[self setVisibleMapRect:mapRect animated:animated];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment