【问题标题】:Mapbox Android determine zoom level that contain all markersMapbox Android 确定包含所有标记的缩放级别
【发布时间】:2014-11-28 03:52:39
【问题描述】:

有没有办法确定缩放级别,以便我的所有标记都适合缩放级别?我正在使用 mapbox 0.4.0

我觉得答案和这个差不多,但是找不到android版本

[https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-only-at-zoom-level/]

【问题讨论】:

    标签: android mapbox


    【解决方案1】:

    使用最新的 SDK 版本,现有答案不再适用。相反,使用这个:

    LatLngBounds latLngBounds = new LatLngBounds.Builder()
      .include(new LatLng(<marker 1 latlng position>)) 
      .include(new LatLng(<marker 2 latlng position>)) 
      .build();
    
    mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 50));
    

    感谢友好的 Mapbox 支持提供此答案:)

    【讨论】:

      【解决方案2】:

      好的,我想通了。我需要创建一个包含所有标记的边界框

      final BoundingBox zoomLevel = findZoomLevel(hotelLocation,poiLocations);
      mv.zoomToBoundingBox(zoomLevel,true,true);
      .....
      
      private BoundingBox findZoomLevel(LatLng hotelLocation, LatLng[] poiLocations) {
              double bottomPadding = 0.002;
              double topPadding = 0.005; 
              BoundingBox box = new BoundingBox(findTopMost(hotelLocation,poiLocations).getLatitude() + topPadding,
                      findRightMost(hotelLocation,poiLocations).getLongitude(),
                      findBottomMost(hotelLocation,poiLocations).getLatitude() - bottomPadding,
                      findLeftMost(hotelLocation,poiLocations).getLongitude());
      
              return box;
      }
      

      更新

      LatLngBounds latLngBounds = new LatLngBounds.Builder()
        .include(new LatLng(lat1,lng1)) 
        .include(new LatLng(lat2,lng2)) 
        .build();
      
      mapboxMap.moveCamera(
      CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, 
                                          int paddingLeft, 
                                          int paddingTop, 
                                          int paddingRight, 
                                          int paddingBottom));
      

      【讨论】:

      • zoomToBoundingBox() 似乎不再可用。有什么选择?
      • @cuddlecheek 像素
      猜你喜欢
      • 2018-12-02
      • 2017-01-24
      • 2020-07-16
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多