Search code examples
androidgoogle-mapsgeolocationopenstreetmaposmdroid

why osmdroid loaded a lot of maps. & Zoom to a wrong place


I am building an app that needs to use OpenStreetMap. The map is loaded. However, when I zoom out I found that there are more than one maps loaded.. in fact, there seems to be infinite numbers of them... One map in the middle, one above and one below; actually if you scroll down the screen, you will see more...

What's the reason? Sorry stackoverflow does not allow me to upload photo. My code is attached and you may wanna try..

Another thing is that, I found my current location latitude and longtitude using location services and stored them in a GeoPoint; then I set the zoom center to that point, but osm went to another point. Very far away.

My code & XML file are attached below

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>

Solution

  • I gues you have more than on archive (maps) in SD card/osmdroid folder and because of that you see more maps.

    For center on your location you can use.

        mMapView.getController().animateTo(yourPosition);