【问题标题】:Tracking mode with MapKit使用 MapKit 的跟踪模式
【发布时间】:2014-05-07 13:53:47
【问题描述】:

我有一个关于 UserLocation e MapKit 的问题。

我会跟随地图上的用户位置(如果用户位置发生变化,会自动移动地图)如果用户点击(或平移或捏合)地图,我会禁用“跟随模式”(如 Apple 地图应用程序) ..

我试过这个方法:

[_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

这很好,但我有一些问题:

  • 是否可以在“跟随模式”期间设置特定的缩放级别?

  • 我注意到,如果他们处于“跟随模式”并且我捏合地图,“跟随模式”模式不会中断。如果我仍然捏地图(或平移)“跟随模式”被中断。我不明白你什么时候真正停止这种模式..

【问题讨论】:

标签: ios mapkit


【解决方案1】:

我想我知道你的方法,你可以试试,MKMapViewDelegate:

func mapView(_mapView:MKMapView,didChangemode:MKUserTrackingMode,animated: Bool) {
    mapView.setUserTrackingMode(.followWithHeading, animated: true)
}

当您滚动或缩放地图视图时,MKUserTrackingMode 会发生变化, 所以你可以重置它。

【讨论】:

    【解决方案2】:

    您可以在其委托方法中将地图的区域或中心设置为用户位置:

    地区:

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 200.0f, 200.0f);
        [self.mapView setRegion:region animated:YES];
    }
    

    中心:

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        [self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
    }
    

    来源:https://stackoverflow.com/a/19518422/3601482

    【讨论】:

      【解决方案3】:

      我猜你想重置追踪模式回到自动跟随:

      [_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
      

      问题是何时重置。我会建议

      • 添加按钮(如 Apple 地图中的导航箭头按钮),以便用户决定何时返回自动跟踪
      • 或制作一个在不活动时重置的计时器

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-27
        • 2021-02-28
        • 1970-01-01
        • 2017-12-05
        • 1970-01-01
        • 2018-02-26
        相关资源
        最近更新 更多