Custom information bubble on tap for overlay items using osmdroid

后端 未结 2 868
不知归路
不知归路 2020-12-10 16:20

I\'m using osmdroid on my new Android project (since I want to be able to use offline maps) but I encounter many difficulties to customize the look \'n feel of the informati

相关标签:
2条回答
  • 2020-12-10 16:45

    EDIT:

    • This answer was best for older google map apis. In google Map V2 this thing is already given.

    You can get the code from https://github.com/galex/android-mapviewballoons

    you can get selected balloon from the method of "BalloonItemizedOverlay.java" as follow

    private void hideOtherBalloons(List<Overlay> overlays) {
            for(int i=0; i<overlays.size();i++ ){
                if (overlays.get(i) instanceof BalloonItemizedOverlay<?> && overlays.get(i) != this) {
                    ((BalloonItemizedOverlay<?>) overlays.get(i)).hideBalloon();
                }else{
                    BalloonOverlayView.SELECTED_BALLOON = i;
                    Log.i(i+" : Baloon Open", BalloonOverlayView.SELECTED_BALLOON+"");
                }
            }
    }
    

    To set the data you can use setBalloonData method of BalloonOverlayView.java file as follow:

    protected void setBalloonData(Item item, ViewGroup parent) {
            if (item.getTitle() != null) {
                title.setVisibility(VISIBLE);
                title.setText(item.getTitle());
            } else {
                title.setText("");
                title.setVisibility(GONE);
            }
            if (item.getSnippet() != null) {
                snippet.setVisibility(VISIBLE);
                snippet.setText(item.getSnippet());
            } else {
                snippet.setText("");
                snippet.setVisibility(GONE);
            }
    }
    
    0 讨论(0)
  • 2020-12-10 16:46

    You should check out this new library, OSM bonus pack. Should do exactly what you want.

    http://code.google.com/p/osmbonuspack/

    0 讨论(0)
提交回复
热议问题