Home How to set a marker snippet when the user taps on the marker in osmdroid map?
Reply: 1

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

himagaran
1#
himagaran Published in 2017-09-14 05:31:10Z

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;

}
Josef Adamcik
2#
Josef Adamcik Reply to 2017-09-18 08:44:27Z

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):

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.348178 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO