2

I have implemented double tap to zoom using following code.

CLLocation* currentLocation = [myArray objectAtIndex:5];
MKMapPoint annotationPoint =  MKMapPointForCoordinate(currentLocation.coordinate);
MKMapRect zoomRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
[mapView setVisibleMapRect:zoomRect animated:YES];

When i double tap first time, zoom to particular pin location not working, next time onwards working fine.

and if double tap from different location very far from pins locations,then same issue i.e. zoom to particular pin location not working.

Can any one have an idea Please?

Thanks

Steve Gear
  • 757
  • 2
  • 16
  • 44
  • It looks like you might be mixing units in your call to `MKMapRectMake`. The width and height of an `MKMapRect` are in map points, which relates to the map projection in the `MKMapView`. The 0.1 values look like you're using small latitude and longitude values rather than map points. – Jeffrey Morgan Aug 24 '16 at 22:43
  • @Jeffrey thanks for the response. Even though i change the 0.1 values that does not effect and getting the same issue. please share any sample code. – Steve Gear Aug 26 '16 at 03:25

1 Answers1

1

To center the map on a coordinate and zoom out to show some longitude and latitude either side of the coordinate, create an MKCoordinateRegion object and update the MKMapView to show the new region:

CLLocation* currentLocation = [myArray objectAtIndex:5];
// Create a span covering 0.1 degrees east to west and north to south
MKCoordinateSpan degreeSpan = MKCoordinateSpanMake(0.1, 0.1);
// Create a region that centers the span on currentLocation
MKCoordinateRegion region = MKCoordinateRegionMake(currentLocation.coordinate, degreeSpan);
// Update the map to show the new region
[mapView setRegion:region animated:YES];

To zoom in further, reduce the size of the degree span, e.g.:

MKCoordinateSpan degreeSpan = MKCoordinateSpanMake(0.05, 0.05);

You can also create regions in meters, which can be easier to reason about. The following creates a 1000 x 1000 meter region:

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(currentLocation.coordinate, 1000, 1000);

To zoom in further, reduce the number of meters.

Jeffrey Morgan
  • 556
  • 1
  • 6
  • 12