Always show map marker title in Android

前端 未结 6 2273
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 04:18

I\'m adding default Marker to GoogleMap the following way:

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.editMapMap)).getMap();

         


        
相关标签:
6条回答
  • 2020-12-06 04:21

    use showInfoWindow() and add marker as below.

    Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
    marker.showInfoWindow();
    
    0 讨论(0)
  • 2020-12-06 04:32

    I know this question is old but I'll post my answer here in case it helps someone.

    Info windows would not work for my case and I wanted the titles to show only if there is room, potentially hiding if not enough room to display so that they don't overlap each other.

    I found no solution on the internet so I rolled up my sleeves and made this library which solves my problem, hopefully it will help others too:

    https://github.com/androidseb/android-google-maps-floating-marker-titles

    Here is a preview of how it works:

    0 讨论(0)
  • 2020-12-06 04:33

    Hold but here is my answer:

    From the documentation, there is an text saying that info window is shown one at time, so there is no way to do that:

    "An info window allows you to display information to the user when they tap on a marker. Only one info window is displayed at a time. If a user clicks on a marker, the current info window will be closed and the new info window will be displayed. Note that if the user clicks on a marker that is currently showing an info window, that info window closes and re-opens."

    Maps api doc says:

    "Best practices: For the best user experience, only one info window should be open on the map at any one time. Multiple info windows make the map appear cluttered. If you only need one info window at a time, you can create just one InfoWindow object and open it at different locations or markers upon map events, such as user clicks. If you do need more than one info window, you can display multiple InfoWindow objects at the same time."

    on https://developers.google.com/maps/documentation/javascript/infowindows

    0 讨论(0)
  • 2020-12-06 04:36

    Just return false for onMarkerClickListener, if you return true shows the infoWindow.

    To hide title when we click on marker:

    map.setOnMarkerClickListener(this);
    ...
    
    @Override
    public boolean onMarkerClick(Marker arg0) {     
      Log.i(TAG,"marker arg0 = "+arg0);               
      return false;
    }
    

    If we return true title will be display, else if we return false title won't display.

    0 讨论(0)
  • 2020-12-06 04:38

    There are two methods for showing and hiding the markers. The boolean return value simply prevents the default behaviour from taking place (false) or allows it to happen (true). In other words, it informs the system whether you consumed the event or not. See Google API Reference.

    private GoogleMap.OnMarkerClickListener onMarkerClickedListener = new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (marker.isInfoWindowShown()) {
                marker.hideInfoWindow();
            } else {
                marker.showInfoWindow();
            }
            return true;
        }
    };
    
    mGoogleMap.setOnMarkerClickListener(onMarkerClickedListener);
    
    0 讨论(0)
  • 2020-12-06 04:39

    It is very easy:

    locationMarker.showInfoWindow();
    
    0 讨论(0)
提交回复
热议问题