Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Marker clicked event is not fired #8236

Closed

Description

@kingfisherphuoc

Platform: Android
Mapbox SDK version: 5.0 Snapshot

Steps to trigger behavior

  1. Set listener for Maker event:
mMapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(@NonNull final Marker marker) {
                LogUtils.e("OnMarkerClick!!!"); // never go here...
                return false;
            }
        });
  1. Add marker into MapView:
    // add marker adapter
    mMapboxMap.getMarkerViewManager().addMarkerViewAdapter(new CustomMarkerAdapter(this.getContext()));
    // add new markerview into mapview
    new CustomMarkerViewOptions().anchor(0.5f, 0.5f).position(marker.getLatLng())

Expected behavior

The onMarkerClick is always called before getInfoWindow(@NonNull final Marker marker)

Actual behavior

The onMarkerClick is never called in this version. Previous SDK version (4.2), the event is always fired before getInfoWindow(@NonNull final Marker marker).

Activity

  1. added
    Android
    on Mar 1, 2017
  2. tobrun commented on Mar 1, 2017

    @tobrun
    Member

    @kingfisherphuoc thank you for reaching out. Instead of hooking into MarkerClickListener you will need to hook into MarkerViewClickListener.

            mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
              @Override
              public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
                Timber.e(marker.toString());
                return false;
              }
            });
  3. kingfisherphuoc commented on Mar 3, 2017

    @kingfisherphuoc
    Author

    @tobrun I tried with MarkerViewClickListener and I have other problems:

    1. It's really hard to trigger this event when the MarkerView is big and complicated. (My Markerview is 100dp width, and I must click at near the bottom center of Marker to trigger the event, otherwise, nothing occurs).
    2. The onMarkerClick is called twice (I am trying to show a dialog when click --> double dialogs occur)
     mMapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
                @Override
                public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
                    LogUtils.e("OnClick");
                    return false;
                }
            });
    
  4. reopened this on Mar 3, 2017
  5. added this to the android-v5.0.0 milestone on Mar 3, 2017
  6. self-assigned this
    on Mar 3, 2017
  7. PhanVanLinh commented on Jun 28, 2017

    @PhanVanLinh

    @kingfisherphuoc The onMarkerClick is called twice (I am trying to show a dialog when click --> double dialogs occur). How do you solve this problem?

  8. AlexSheiko commented on Jul 23, 2017

    @AlexSheiko

    @kingfisherphuoc, I have the same problem. Using Mapbox 5.0.2, I believe.

    I'm attempting to open activities instead of dialogs, so as a temporary workaround I added android:launchMode="singleInstance" to the manifest file of the target activity.

  9. grote commented on Oct 19, 2017

    @grote

    Instead of hooking into MarkerClickListener you will need to hook into MarkerViewClickListener.

    @tobrun I just ran into this myself and would suggest you at least improve the documentation here.

    MapboxMap#setOnMarkerClickListener() says:

    Sets a callback that's invoked when the user clicks on a marker.
    

    This sounds like it would do what I want it to do. For me it is still not clear what the difference to the other method is.

  10. tobrun commented on Oct 19, 2017

    @tobrun
    Member

    @grote thank you for the ping! I'm not going to add this to the javadoc as we are deprecating markerView in total and you won't be running in this issue anymore since #9365

  11. beefarm commented on Nov 9, 2017

    @beefarm

    @tobrun just upgraded from 4.2.0 to 5.2.0, and like others I am seeing the issue of onMarkerCick no longer being fired as mentioned here and in 8159. My (previously working) code is essentially identical to that of the original poster. Not clear what the solution is, as early suggestions were to instead use MarkerViewClickListener, but that is apparently being deprecated.

  12. tobrun commented on Nov 9, 2017

    @tobrun
    Member

    MarkerViews in total have been deprecated not just the clicklistener

  13. igor-martucelli commented on Nov 9, 2017

    @igor-martucelli

    Hi guys, here may not be the right place for this question, but @tobrun would like to know if it is possible to identify a double click on the map marker, or on the map itself, since I need to do an action if a map item have a double click ....

  14. tobrun commented on Nov 9, 2017

    @tobrun
    Member

    @igor-nm a double tap gesture is recognize as a zoom in gesture. Afaik we don't allow overriding that behaviour though you could try with MapView#OnTouch.

  15. igor-martucelli commented on Nov 9, 2017

    @igor-martucelli

    Thank you @tobrun, I go testing this method

  16. beefarm commented on Nov 9, 2017

    @beefarm

    @tobrun wrote

    MarkerViews in total have been deprecated not just the clicklistener

    Understood, which is why I asked. So how does one get a custom onMarkerClick to fire with 5.x (as it did in 4.x but no longer seems to), given that the previously-offered solution of using

    mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener...

    has been deprecated? I need to fire a custom behavior, and not show an InfoWindow, when a marker is clicked, and that no longer seems to work with 5.x.

    Thanks -

  17. malexandersalazar commented on Feb 10, 2018

    @malexandersalazar

    So, what should I do to handle the click event for a custom marker? Nothing works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Android

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions