【问题标题】:OSMDROID displays multiple maps with polylines in AndroidOSMDROID 在 Android 中显示多条带折线的地图
【发布时间】:2020-04-13 17:34:53
【问题描述】:

当我启动我的 android 应用程序时,我看到多个带有折线的地图。我怎样才能只显示一张地图?

MainActivity:

public class MainActivity extends AppCompatActivity {

    MapView map;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context ctx = getApplicationContext();
        Configuration.getInstance().load(ctx,    PreferenceManager.getDefaultSharedPreferences(ctx));
        setContentView(R.layout.activity_main);



       map = findViewById(R.id.mapViewMain);
       map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
       map.setBuiltInZoomControls(true);
       map.setMultiTouchControls(true);

    }

    protected void onResume() {
        super.onResume();       
        map.onPause();  
    }

    protected void onPause() {
        super.onPause();
        map.onPause();
    }


}

布局activity_main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <org.osmdroid.views.MapView
        android:id="@+id/mapViewMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

我只想在我的设备上查看一张地图。

【问题讨论】:

标签: android maps osmdroid


【解决方案1】:

我用这个解决了这个问题:

MapView map = (MapView) findViewById(R.id.map);
map.setScrollableAreaLimitDouble(new BoundingBox(85, 180, -85, -180));
map.setMaxZoomLevel(20.0);
map.setMinZoomLevel(4.0);
map.setHorizontalMapRepetitionEnabled(false);
map.setVerticalMapRepetitionEnabled(false);
map.setScrollableAreaLimitLatitude(MapView.getTileSystem().getMaxLatitude(), MapView.getTileSystem().getMinLatitude(), 0);

【讨论】:

    【解决方案2】:

    您的代码是正确的,您实际上只看到一张地图 - 仅在地图组件上表示。地图缩小太多,比视图小。 osmdroid 库通过在视口中重复映射来解决这个问题。我认为没有办法关闭此功能。

    你可以通过设置一些合理的缩放级别来解决这个问题。

    map.setZoomLevel(12)
    

    【讨论】:

    • @dEod 很抱歉,我不明白你的问题。
    • 我解决了 map.setScrollableAreaLimitDouble(new BoundingBox(85, 180, -85, -180));
    【解决方案3】:
    MapView map;
    map.setHorizontalMapRepetitionEnabled(true);
    map.setVerticalMapRepetitionEnabled(false);
    map.setScrollableAreaLimitLatitude(MapView.getTileSystem().getMaxLatitude(), MapView.getTileSystem().getMinLatitude(), 0); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-23
      • 2020-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多