当animateCamera大小不能为零时例外

时间:2017-10-24 11:30:55

标签: maps size

在Android上,当animateCamera(cu)时我有一个例外。我看到很多例子,我看不出代码中有什么不同。 有人有想法吗?

Bounds具有这些值(在调试时看到): northeast lat / lng:(43.6026,1.50275) 西南拉特/伦:(43.5578,1.4243)

记录: com.google.maps.api.android.lib6.common.apiexception.c:使用newLatLngBounds时出错(LatLngBounds,int):地图大小不能为0.很可能,地图视图尚未出现布局。要么等到布局发生,要么使用newLatLngBounds(LatLngBounds,int,int,int),它允许你指定地图的尺寸​​。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
  <div class="container">

    <a href="#" class="logo"></a>
    <nav class="site-nav">
      <ul>
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a>
          <ul>
            <li><a href="#">Link 2.1</a></li>
            <li><a href="#">Link 2.1</a>
              <ul>
                <li><a href="#">Link 2.1.1</a></li>
                <li><a href="#">Link 2.1.2</a></li>
                <li><a href="#">Link 2.1.3</a></li>
                <li><a href="#">Link 2.1.4</a></li>
              </ul>
            </li>
            <li><a href="#">Link 2.1</a></li>
          </ul>
        </li>
        <li><a href="#">loooooong</a>
          <ul>
            <li><a href="#">Link 3.1</a></li>
            <li><a href="#">Link 3.2</a></li>
            <li><a href="#">Link 3.3</a></li>
            <li><a href="#">loooooooooooooooooong</a></li>
            <li><a href="#">Link 3.5</a></li>
          </ul>
        </li>
        <li><a href="#">Link 4</a></li>
        <li><a href="#">Link 5</a></li>
        <li><a href="#">Link 6</a></li>
        <li><a href="#">Link 7</a>
          <ul>
            <li><a href="#">Link 7.1</a></li>
            <li><a href="#">Link 7.2</a></li>
            <li><a href="#">Link 7.3</a>
              <ul>
                <li><a href="#">Link 7.3.1</a></li>
                <li><a href="#">Link 7.3.2</a></li>
                <li><a href="#">loooooooong</a></li>
                <li><a href="#">Link 7.3.4</a></li>
                <li><a href="#">Link 7.3.5</a></li>
              </ul>
            </li>
            <li><a href="#">Link 7.4</a></li>
            <li><a href="#">Link 7.5</a></li>
          </ul>
        </li>
        <li><a href="#">Link 8</a></li>
      </ul>
    </nav>

  </div>
</header>

1 个答案:

答案 0 :(得分:1)

Itr使用它,在别人的答案中找到并适应我的代码

// Cannot zoom to bounds until the map has a size.
        final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).getView();
        if (mapView != null) {
            if (mapView.getViewTreeObserver().isAlive()) {
                mapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation") // We use the new method when supported
                    @SuppressLint("NewApi") // We check which build version we are using.
                    @Override
                    public void onGlobalLayout() {
                        Log.d("$$NAV ", "onGlobalLayout");
                        //Calculate the markers to get their position
                        if (isMapOk) {
                            LatLngBounds bounds = builder.build();
                            googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 70));
                        } //ongloballayout
                        else // map is not OK (no polyline) -> center // message 48°51'19.9"N 2°18'57.1"E
                        {
                            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(48.855484, 2.315972), 0)); // "Le Penseur" of Rodin, Rodin museum in Paris
                        }
                    }
                });
            }//if (mapView!=null)
        }