Auto scroll mkmapview when dragging pin

690 views Asked by At

Is there any good code which implements auto scrolling of MKMapView when dragging pin?

The effect I'm trying to achieve is a map scrolling when I drag the pin and reach edges of the map. When I move pin out of the edges I expect scrolling to stop and when I drop it, map shell move until pin reaches center of the screen.

I know how to center map on chosen location, but I'm not really have an idea how to scroll it while dragging pin.

It would really help if someone could just direct me to a logic of the way how to implement it.

1

There are 1 answers

0
karthika On
MKMapRect mapRect = [self.mapView visibleMapRect];

CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(42.777126,-76.113281);

MKMapPoint point = MKMapPointForCoordinate(coordinate);
mapRect.origin.x = point.x - mapRect.size.width * 0.3;
mapRect.origin.y = point.y - mapRect.size.height * 0.70;

[self.mapView setVisibleMapRect:mapRect animated:YES];