I create 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 want to get its coordinates when each of them is dragged / deleted, 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 the problem is creating markers, because Android Studio says that the variables M0 and M2 are never used. Also I'm not sure if using mMap.setOnMarkerDragListener (the new OnMarkerDragListener () {helps twice. How can I fix this?
Thank.
source
share