How to disable android map marker click auto center

前端 未结 4 1900
我在风中等你
我在风中等你 2020-12-29 02:37

I am looking for a way to disable my map fragment\'s auto centre on selected marker functionality. I still want the markers InfoWindow to show up, but just not centre the en

相关标签:
4条回答
  • 2020-12-29 02:57

    Very Simple:

    Use below code for implement setOnMarkerClickListener().

    @Override
    public boolean onMarkerClick(Marker marker) {
    
        marker.showInfoWindow(); // show info window
    
        return true; // can't move map by this
    } 
    
    0 讨论(0)
  • 2020-12-29 03:01

    Simple way:

    1. Implement setOnMarkerClickListener()
    2. Return 'TRUE' to prevent GoogleMap by default moves the map center to the marker.

    Example:

    map.setOnMarkerClickListener(
        new OnMarkerClickListener() {
            boolean doNotMoveCameraToCenterMarker = true;
            public boolean onMarkerClick(Marker marker) {
                //Do whatever you need to do here ....
                return doNotMoveCameraToCenterMarker;
            }
        });
    
    0 讨论(0)
  • 2020-12-29 03:09

    Take a look at the following post:

    Don't snap to marker after click in android map v2

    There is a method given there by @DMan, basically you need to consume the OnMarkerClick event and override the default behavior:

    // Since we are consuming the event this is necessary to
    // manage closing openned markers before openning new ones
    Marker lastOpenned = null;
    
    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
    public boolean onMarkerClick(Marker marker) {
        // Check if there is an open info window
        if (lastOpenned != null) {
            // Close the info window
            lastOpenned.hideInfoWindow();
    
            // Is the marker the same marker that was already open
            if (lastOpenned.equals(marker)) {
                // Nullify the lastOpenned object
                lastOpenned = null;
                // Return so that the info window isn't openned again
                return true;
            } 
        }
    
        // Open the info window for the marker
        marker.showInfoWindow();
        // Re-assign the last openned such that we can close it later
        lastOpenned = marker;
    
        // Event was handled by our code do not launch default behaviour.
        return true;
    }
    });
    
    0 讨论(0)
  • 2020-12-29 03:09

    Simple. Add moveOnMarkerPress prop to MapView and set it to false.

     <MapView
          moveOnMarkerPress={false}
    >
    
    0 讨论(0)
提交回复
热议问题