【问题标题】:MKMapView: Follow Current Location with current zoom levelMKMapView:以当前缩放级别跟随当前位置
【发布时间】:2011-12-04 04:55:14
【问题描述】:

我有一种方法可以移动地图,使其跟随当前用户位置。这很好用,但目前缩放比例不能按我想要的方式工作。我希望用户能够按照他们想要的方式缩小或放大地图,并且仍然让它跟随用户刚刚在地图上设置的新缩放比例的当前位置。

我尝试执行以下操作,但效果不佳:

/**
 * Centers the map on the current location
 *
 * @version $Revision: 0.1
 */
- (void)centerMapOnLocation:(CLLocation *)location {

    // Make a region using our current zoom level
    CLLocationDistance latitude = mapView.region.span.latitudeDelta*100;
    CLLocationDistance longitude = mapView.region.span.longitudeDelta*100;
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, latitude, longitude);
    [mapView setRegion:region animated:YES];
}//end

【问题讨论】:

    标签: iphone ios mkmapview core-location


    【解决方案1】:

    MKMapView Zoom and Region 描述了如何获取当前视图窗口。

    当您创建新的MKCoordinateRegion 以将新视图设置为时,请使用允许您指定大小的构造函数:

    UIKIT_STATIC_INLINE MKCoordinateRegion MKCoordinateRegionMake(
       CLLocationCoordinate2D centerCoordinate,
       MKCoordinateSpan span
    );
    

    您需要从当前区域传入span,从用户位置传入centerCoordinate,我认为您已经得到了。

    【讨论】:

    • 不确定你的意思。我可以从 mapView.region.span 获得跨度,所以我不需要创建一个新的。
    • 没错。但是,如果要将其移动到当前用户的位置,则需要创建一个新的 MKCoordinateRegion 来将 mapView 设置为。但是,如果你使用 MKCoordinateRegionMakeWithDistance 进行设置,那么跨度将重置为某个默认值。相反,使用 MKCoordinateRegionMake 制作它,并将 current 跨度传递给它,这样跨度就不会改变。
    • 啊,我需要使用 MKCoordinateRegionMake 而不是 MKCoordinateRegionMakeWithDistance。谢谢!
    猜你喜欢
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多