Get position from two markers - onMarkerDragEnd

android, google-maps

Solution

the `OnMarkerDragListener` is for all the markers that are draggable and not individual markers so declaring 2 listeners with different names does nothing.

what you need to do is either hold onto the marker when your create them and then see if the marker you are dragging is `m0` or `m2` or you can check the marker id's to see what one it is

Problem

I´m creating the markers like this: ``` Marker MO = mMap.addMarker(new MarkerOptions() .position(latLng) .draggable(true) .icon(BitmapDescriptorFactory.fromBitmap(icon)) ); Marker M2 = mMap.addMarker(new MarkerOptions() .position(latLng) .draggable(true) .icon(BitmapDescriptorFactory.fromBitmap(icon2)) ); ``` And i wish to get its coordinates when each one are drag/dropped, but when using this: ``` mMap.setOnMarkerDragListener(new OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker M0) { } @Override public void onMarkerDragEnd(Marker M0) { LatLng pos = M0.getPosition(); TextView err = (TextView)findViewById(R.id.text1); err.setText("M0" + pos.latitude + "," + pos.longitude); } @Override public void onMarkerDrag(Marker M0) { } }); mMap.setOnMarkerDragListener(new OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker M2) { } @Override public void onMarkerDragEnd(Marker M2) { LatLng pos2 = M2.getPosition(); TextView err2 = (TextView)findViewById(R.id.text2); err2.setText("M2" + pos2.latitude + "," + pos2.longitude); } @Override public void onMarkerDrag(Marker M2) { } }); ``` I can get the coordinates from both markers, but the coordinates from M0 are attached to M2 "text". I think that the problem is in creating the markers, because Android Studio says that M0 and M2 variables are never used. Also i´m not sure if using mMap.setOnMarkerDragListener(new OnMarkerDragListener() { twice is helping. How can i fix this? Thanks.

Original source