开发者

How to add a zoom in and zoom out button to map in iPhone

I have a map in which I want to add 2 buttons viz. zoom in and zoom out. On the click of first button my should zoom in and on the click of second button my map should zoom out. How 开发者_运维百科is this possible?


Zoom IN:

- (IBAction) zoomInClicked:(id)sender
{
    // when zoom button is clicked, zoom on a specific region
    // make region for the map to show as zoom in

    [myMapView setRegion:region animated:YES];

}

zoom Out:

- (IBAction)zoomOutClicked:(id)sender
{
    // make region for the map to show as zoom out
    [mapView setRegion:region animated:YES];
}


You can't explicitly set a zoom level for the MKMapView. Instead you set a visible region

You do this by setting the region property of the map. A region is defined by a center point and a horizontal and vertical distance, referred to as the span. The span defines how much of the map at the given point should be visible and is also how you set the zoom level. Specifying a large span results in the user seeing a wide geographical area and corresponds to a low zoom level. Specifying a small span results in the user seeing a more narrow geographical area and corresponds to a higher zoom level.

So your two buttons need to adjust the span property of the MKCoordinateRegion type. Increasing the longitudeDelta & latitudeDelta will zoom out, decreasing them will zoom in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜