Himagaran
Himagaran

Reputation: 312

How to set a marker snippet when the user taps on the marker in osmdroid map?

Below is my implementation and I can't see any description on my marker when I tap on it. I even went through many sources but couldn't fetch a working one. Looking for a positive way out.

public Marker addMarker(GeoPoint p) {

    Marker marker = new Marker(osm);
    marker = new Marker(osm);
    marker.setPosition(p);
    osm.getOverlays().add(marker);
    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    marker.setIcon(getResources().getDrawable(R.drawable.black));
    marker.setTitle("Marker");
    marker.setSnippet("Snippet marker");
    marker.setSubDescription("SubDescription marker");
    return marker;

}

Upvotes: 1

Views: 1595

Answers (1)

Josef Adamcik
Josef Adamcik

Reputation: 5780

Your code is correct and should work. You should use latest version of openstreetmap library and modify code accordingly. Latest version is 5.6.5 at the moment.

Quickly crafted example is giving this result (after tap):

enter image description here

I had to comment out this line:

marker.setIcon(getResources().getDrawable(R.drawable.black));

Because I don't have the drawable.

Classes you are using from osmbonuspack are no longer there because they were moved to osmdroid library. You will have to change your imports (e.g. to org.osmdroid.views.overlay.Marker etc). You can remove osmbonuspack dependency completely because code you provided does not need it.

You will have to change a construction of a tile source:

osm.setTileSource(TileSourceFactory.MAPNIK);

(But please keep in mind there is a usage policy for openstreetmap tiles.)

Final note: Common problem with markers is when you set custom onMarkerClickListener, than the default implementation isn't called. You would need to open marker window from your listener by calling marker.showInfoWindow(). But this is not your problem.

Upvotes: 1

Related Questions