1

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;

}
Mohit Tyagi
  • 2,788
  • 4
  • 17
  • 29
Himagaran
  • 312
  • 2
  • 14
  • Do you see a bubble(InfoWindow) without text or you don't see a bubble at all? It there any code setting an onClickListener to the marker after creation? – Josef Adamcik Sep 14 '17 at 08:09
  • I dont see a bubble at all and i create new objects for each marker geopoints – Himagaran Sep 14 '17 at 08:47
  • Ok, second question again: Are you calling marker.setOnMarkerClickListener(...) anywhere? It's not in code you posted but I dont' know what do you do with returned value. – Josef Adamcik Sep 14 '17 at 08:52
  • No i haven't used any marker listeners and i'm pretty unsure how that can be done. Anyway you can see my implementation here : https://drive.google.com/file/d/0ByXacZESDmJRV1FHVEZ1SVY4R1k/view?usp=sharing – Himagaran Sep 14 '17 at 09:03
  • Which versions of osmdroid and osmbonuspack are you using? Your code cannot be compiled with the letest versions. – Josef Adamcik Sep 14 '17 at 10:45

1 Answers1

1

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.

Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42
  • Hey thanks for the effort, I'm glad its working in yours. I need to clarify one thing : This link https://drive.google.com/file/d/0ByXacZESDmJRQWYzblNINEY5Zjg/view shows my external libraries with their versions under libs section. I still face the same issue even after upgrading the libraries into latest versions – Himagaran Sep 15 '17 at 11:01
  • @himagaran Why are you using obsolete versions of libraries? There's osmdroid 4.3 in your project. There may be bugs and problems in older versions. I usually can find solution to problems by reading source code of a library. But I don't think I wont to go and study those old versions because it's not worth it. Also why don't you use gradle? You already asked about latest version of osmdroid via gradle: https://stackoverflow.com/questions/45930978/i-get-an-error-on-getinstance-method-even-though-i-followed-the-osmdroid-docum and you got answer to your question. – Josef Adamcik Sep 15 '17 at 11:10
  • I stopped gradle due to low memory on my pc. Anyway i'll check into it again and let you know. Thanks again – Himagaran Sep 15 '17 at 11:25
  • @himagaran I see. Gradle can be greedy. You can download a zip with the latest version (link to page with downloads is in my answer). There is aar file with osmdroid library. As far as I know, you can use it even without gradle. (Check this https://stackoverflow.com/questions/23777423/aar-in-eclipse-ant-project ). – Josef Adamcik Sep 15 '17 at 11:57
  • i did the steps as mentioned in above comment. but it gives a error in (import org.osmdroid.ResourceProxy;) in this line saying cannot be found. i can't remove that line because i use it for loading my custom map. – Himagaran Sep 18 '17 at 07:09
  • @himagaran And what should it do? There's no such class in the current version so I have no clue what is its purpose. I managed to remove it in my quick example which I used to take the screenshot above, but as you can see tiles are not loaded. – Josef Adamcik Sep 18 '17 at 07:46
  • 1
    @himagaran Ok, I've found it. I updated my response with an example how you can fix the problem. – Josef Adamcik Sep 18 '17 at 08:35
  • Hey, i use OnlineTileSourceBase not TileSourceFactory. Anyway i managed to make it from another method which can be seen from this https://www.thiengo.com.br/markerinfowindow-no-openstreetmap-android and here is how my map looks now https://drive.google.com/open?id=0ByXacZESDmJRSzlzZ3paV3ZIdmc By the way, I'm very glad that this issue can be solved in two ways now. Thanks with your effort! – Himagaran Sep 19 '17 at 05:11