0
我有一个简单的Android应用程序。我试图展示一个简单的地图(就像我们在Google地图中一样)。在OSMDroid网站之后,我按照指示安装了应用程序。OSMDroid显示多个地图和无限滚动
我有清单文件,如下图所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sample.osmdroid.com.osmdroidsample">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我有如下图所示我MainActivity.java
:
public class MainActivity extends AppCompatActivity {
ArrayList<OverlayItem> anotherOverlayItemArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);
//important! set your user agent to prevent getting banned from the osm servers
Configuration.getInstance().load(getApplicationContext(), PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
setContentView(R.layout.activity_main);
MapView map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(2);
map.setMaxZoomLevel(3);
map.setMinZoomLevel(2);
}
@Override
protected void onRestart() {
super.onRestart();
//this will refresh the osmdroid configuration on resuming.
//if you make changes to the configuration, use
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Configuration.getInstance().save(this, prefs);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
}
}
相应的布局文件activity_main.xml
如下图所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="sample.osmdroid.com.osmdroidsample.MainActivity">
<TextView
android:id="@+id/myTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_below="@id/myTxt"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.osmdroid.views.MapView android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
默认输出如下所示:
问题: 当我滚动地图向上/向下或横盘整理,该出把原来是这样的:
正如您上面的图片出现在看不是屏幕中的单个地图。当你滚动时,它们的数量是无限的,地图不停地滚动(水平和垂直滚动)。
我的要求是像我们在Google Map API中那样只有一个地图实例。那么如何使用OSMDroid实现相同?
P.S. I cannot use Google Maps API as the same is not supported in China.
感谢您的答复。但需要更多细节。单个地图占用的区域是什么(以便我可以设置可滚动区域)?世界是圆形/球形的,但我们的表示是在一个平面屏幕上,所以我只需要一个地图实例。 – Zax
我还没有尝试过,但我的猜测是指定一个从'> -90'到'<90'和从'> -180'到'<180'的经纬度的边界框。 – scai