CodeIsLaw
CodeIsLaw

Reputation: 345

map is not visible in OpenStreetMap (osm)

My goal is it to build a simple app for android. The app needs some map data from OpenStreetMap (OSM). I made the decision to use osmdroid for my litle project. and now I am close to the result I want to see, there is just one small difficulty for me. If I try to run the app now there is no mistake (exceptions or errors) but unfortunately I don't see a map:

empty osm view

My guess is that my commandline in the @Override public void onCreate() class is needed. but if I remove the commandline and make it to "real code" there is an error with the method getInstance().load(...) so my thoughts are that there is something wrong with my Configuration class. there are no suggestion for my code to find/remove the error

thats my MainActivity.java class:


import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.views.MapView;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;

import org.osmdroid.views.MapView;

public class MainActivity extends Activity {

    MapView map = null;
    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        Context ctx = getApplicationContext();
        //Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

        setContentView(R.layout.activity_main);

        map = (MapView) findViewById(R.id.map);
        map.setTileSource(TileSourceFactory.MAPNIK);
    }

    public void onResume(){
        super.onResume();
        map.onResume();
    }

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

}```

Upvotes: 1

Views: 932

Answers (1)

CodeIsLaw
CodeIsLaw

Reputation: 345

I found the anwser by myself. The mistake was the wrong import. import android.content.res.Configuration; This is the correct one: import org.osmdroid.config.Configuration; my actual mainActivity looks like this now:


import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;

import android.app.Activity;
import android.content.Context;
import org.osmdroid.config.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;


public class MainActivity extends Activity {

    MapView map = null;
    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        Context ctx = getApplicationContext();

        Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));


        setContentView(R.layout.activity_main);

        map = (MapView) findViewById(R.id.map);
        map.setTileSource(TileSourceFactory.MAPNIK);

        map.setBuiltInZoomControls(true);
        map.setMultiTouchControls(true);



        IMapController mapController = map.getController();
        mapController.setZoom(13);

        GeoPoint startPoint = new GeoPoint(52.516181, 13.376935);
        mapController.setCenter(startPoint);
    }

    public void onResume(){
        super.onResume();
        map.onResume();
    }

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



}```

Upvotes: 2

Related Questions