Lucas Bullen
Lucas Bullen

Reputation: 211

current viewing coordinates on map for zooming tools

My final goal is to have buttons to zoom in and out on the map, but I am stuck in finding a way to keep the center coordinates the same as I zoom. How should I go about doing this?

Upvotes: 1

Views: 56

Answers (1)

Rob
Rob

Reputation: 438112

You can do something like the following, which grab's the map's current region, leaves the center unchanged, but adjusts the span:

- (IBAction)zoomIn:(id)sender {
    MKCoordinateRegion region = self.mapView.region;
    region.span.latitudeDelta /= 2.0;
    region.span.longitudeDelta /= 2.0;
    [self.mapView setRegion:region animated:YES];
}

- (IBAction)zoomOut:(id)sender {
    MKCoordinateRegion region = self.mapView.region;
    region.span.latitudeDelta  = MIN(region.span.latitudeDelta  * 2.0, 180.0);
    region.span.longitudeDelta = MIN(region.span.longitudeDelta * 2.0, 180.0);
    [self.mapView setRegion:region animated:YES];
}

Upvotes: 1

Related Questions