我正在构建一个需要使用OpenStreetMap的应用程序。地图已加载。但是,当我缩小时,我发现加载了多个地图。事实上,它们的数量似乎是无限的……一张地图在中间,一张在上面,一张在下面;实际上,如果你向下滚动屏幕,你会看到更多……
理由是什么呢?抱歉,stackoverflow不允许我上传照片。我的代码附在附件中,你可能想试试..
另一件事是,我使用定位服务找到了我当前的位置纬度和经度,并将它们存储在GeoPoint中;然后我将缩放中心设置为该点,但osm转到了另一个点。很远的地方。
我的代码和XML文件附在下面
public class OsmdActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(10);
double lat = 1.29377413882149 * 1000000;
double lon = 103.771969817518 * 1000000;
GeoPoint p = new GeoPoint(lat, lon);
mapController.setCenter(p);
}}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.osmdroid.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"/>
</LinearLayout>
发布于 2012-05-09 15:46:24
我猜你在SD卡/osmdroid文件夹中有更多的存档(地图),因此你会看到更多的地图。
对于您所在位置的中心,您可以使用。
mMapView.getController().animateTo(yourPosition);
发布于 2014-08-13 06:27:56
对我来说,我不能在创建活动时设置中心。如果我在你设置中心点之前等待大约200ms,一切都会正常工作。
这是一个丑陋的解决方案:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
GeoPoint point = new GeoPoint((int) (52.520820* 1E6),(int) (13.409346* 1E6));
mapView.getController().animateTo(point);
}
}, 200);
发布于 2015-09-07 13:51:04
在osmdroid 4.3版本中,应该已经修复了有关在某个位置居中的问题。对于4.3版及更高版本,不再需要使用postDelayed的解决方法。
详细信息:通过以下对osmdroid的提交,以前需要布局才能正常工作的"animateTo()“等调用现在将被记录下来,并在布局创建后自动重播。
https://github.com/osmdroid/osmdroid/commit/2f38d49281b31e79a8290d8df55bb738024907e8
https://stackoverflow.com/questions/10509130
复制相似问题