我将地图设置为旋转到用户位置。如何允许用户与地图互动?

时间:2019-05-30 00:25:22

标签: ios swift cllocation

我将地图设置为居中并旋转到用户的位置和方向,但是地图视图已锁定,因为无法与之交互。

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">

<div class="table-responsive">
  <table class="table table-bordered table-condensed table-fixed" id="StoreData">
    <thead>
      <tr>
        <th class="col-xs-4">County / District</th>
        <th class="col-xs-2">Zip Code</th>
        <th class="col-xs-3">Longitude</th>
        <th class="col-xs-3">Latitude</th>
      </tr>
    </thead>
    <tr>
      <td>
        <div>Bermuda Triangle</div>
      </td>
      <td>
        <div>33036</div>
      </td>
      <td>
        <div>25.0000</div>
      </td>
      <td>
        <div>-71.0000</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
    <tr>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
      <td>
        <div>&nbsp;</div>
      </td>
    </tr>
  </table>
</div>

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>

我如何允许用户探索周围的环境;滚动,缩放,与图钉交互等,同时使用户居中并旋转?

2 个答案:

答案 0 :(得分:2)

通过使用didUpdateLocations委托方法,您将不断更新地图视图,从而覆盖用户所做的任何更改。

解决方案是不使用CLLocationManager委托方法来更新地图视图。

只需将地图上的userTrackingMode设置为.followWithHeading,地图视图就会为您完成工作。用户与地图互动后,跟踪模式将更改为.none

您可以添加一个按钮以重新激活.followWithHeading用户跟踪模式。

答案 1 :(得分:0)

这就是我最终完成的工作,并且效果很好。

func centerViewOnUserLocation() { mapView.setUserTrackingMode(.followWithHeading, animated:true)}