mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.37k stars 1.33k forks source link

The getId() of marker which i clicked is not same to which i have added About Android SDK #4163

Closed Trinea closed 8 years ago

Trinea commented 8 years ago

I have added a marker on map, but when i clicked the marker, its getId() is not same to the marker I have added before. this caused to i cannot distinguish markersin public boolean onMarkerClick(@NonNull Marker marker)

Example code:

private MapView mv;

protected void onCreate(Bundle savedInstanceState) {
    ……
    mv.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(@NonNull Marker marker) {
            Log.e("mapboxtest", "click mark" + marker.getId());
            return false;
        }
    });

    Marker marker = mv.addMarker(new MarkerOptions().title("Edinburgh").snippet("Scotland").icon(IconFactory.getInstance(context).fromResource(R.drawable.ic_launcher)).position(new LatLng(55.94629, -3.20777)));
    Log.e("mapboxtest", "add mark" + marker.getId());
    ……
}

and the output of logcat after i clicked the marker be added is:

03-02 02:18:12.099 20519-20519/com.mapbox.mapboxandroiddemo E/mapboxtest: add mark0
03-02 02:18:34.776 20519-20519/com.mapbox.mapboxandroiddemo E/mapboxtest: click mark1
tobrun commented 8 years ago

I tried reproducing this issue with current state of master but I'm not getting the same result.

See this clip:

This is the code I used in MainActivity.java:

                mMapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
                    @Override
                    public void onMapLongClick(@NonNull LatLng point) {
                        MarkerOptions marker = new MarkerOptions()
                                .position(point)
                                .title("Dropped Pin")
                                .snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
                                        LAT_LON_FORMATTER.format(point.getLongitude()));
                        mMarkerList.add(marker);
                        Marker m = mapboxMap.addMarker(marker);
                        Snackbar.make(mCoordinatorLayout, "Marker added with id "+m.getId(),Snackbar.LENGTH_SHORT).show();
                    }
                });

                mMapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
                    @Override
                    public boolean onMarkerClick(@NonNull Marker marker) {
                        Snackbar.make(mCoordinatorLayout, "Marker Click on marker with id  " + marker.getId(), Snackbar.LENGTH_SHORT).show();
                        return false;
                    }
                });

Sorry for not being able to give you the commit where this was fixed. A lot has changed over the lasts months and it's hard to keep track on all the changes. Going to close this issue for now, reopen if you can reproduce this with the SNAPSHOT.

Trinea commented 8 years ago

ok