如何将mapview中已经缩放的位置更改为当前设备位置

时间:2012-01-30 11:48:32

标签: iphone ios geolocation mkmapview

我正在将mapview加载到viewcontroller的视图中。当我加载mapview时,它会直接缩放到联系人的位置。我在viewcontroller的工具栏中有按钮。当我点击此按钮时,mapview应该从已经缩放的位置缩放到我的iphone的当前位置。此功能类似于iPhone地图应用程序中的功能。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

//did update user location


  - (void)mapView:(MKMapView *)currentMapView didUpdateUserLocation:(MKUserLocation *)userLocation{

        if(shouldChangeSpan) {
           MKCoordinateSpan span;
           span.latitudeDelta = 0.40;
           span.longitudeDelta = 0.45;
           MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, span);
            [mapView setRegion:region animated:YES]; 
            shouldChangeSpan = NO;
        }
    }

shouldChangeSpan在h中声明的bool中。并且在视图中设置为no加载,并在按钮操作方法中设置为yes。

相关问题