[BUG] Fixed an issue where multiple markers where added
Previously instead of moving the existing marker, always a new marker was added. Now the existing marker is replaced.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MapStyleOptions;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
@@ -101,6 +102,11 @@ public class ShareLocationActivity extends AppCompatActivity implements OnMapRea
|
||||
*/
|
||||
private boolean mIsNightMode;
|
||||
|
||||
/**
|
||||
* Reference to the Google Maps Marker, to update it's position rather than adding a new one.
|
||||
*/
|
||||
private Marker mGmapsMarker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -168,9 +174,13 @@ public class ShareLocationActivity extends AppCompatActivity implements OnMapRea
|
||||
|
||||
final LatLng received = new LatLng(locationObject.getLatitude(), locationObject.getLongitude());
|
||||
|
||||
mGmap.addMarker(new MarkerOptions()
|
||||
.position(received)
|
||||
.title(mCurrentUser.getDisplayName()));
|
||||
if (mGmapsMarker == null) {
|
||||
mGmap.addMarker(new MarkerOptions()
|
||||
.position(received)
|
||||
.title(mCurrentUser.getDisplayName()));
|
||||
} else {
|
||||
mGmapsMarker.setPosition(received);
|
||||
}
|
||||
mGmap.moveCamera(CameraUpdateFactory.newLatLngZoom(received, 15.0f));
|
||||
|
||||
}
|
||||
@@ -207,7 +217,13 @@ public class ShareLocationActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
final LatLng defaultHome = new LatLng(48.41965746149261, 9.909289365473684);
|
||||
|
||||
mGmap.addMarker(new MarkerOptions().position(defaultHome).title("Default - Home"));
|
||||
if (mGmapsMarker == null) {
|
||||
mGmap.addMarker(new MarkerOptions()
|
||||
.position(defaultHome)
|
||||
.title("Default - Home"));
|
||||
} else {
|
||||
mGmapsMarker.setPosition(defaultHome);
|
||||
}
|
||||
mGmap.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultHome, 15.0f));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user