[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:
Alexander Dörflinger
2025-03-19 16:23:42 +01:00
parent f6abb8fac0
commit 5ec30a966f
2 changed files with 34 additions and 5 deletions

View File

@@ -3,7 +3,20 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State /> <State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="47111FDAS0039V" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2025-03-19T15:23:01.624733903Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>

View File

@@ -20,6 +20,7 @@ import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions; 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.android.gms.maps.model.MarkerOptions;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.FirebaseUser;
@@ -101,6 +102,11 @@ public class ShareLocationActivity extends AppCompatActivity implements OnMapRea
*/ */
private boolean mIsNightMode; private boolean mIsNightMode;
/**
* Reference to the Google Maps Marker, to update it's position rather than adding a new one.
*/
private Marker mGmapsMarker;
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -168,9 +174,13 @@ public class ShareLocationActivity extends AppCompatActivity implements OnMapRea
final LatLng received = new LatLng(locationObject.getLatitude(), locationObject.getLongitude()); final LatLng received = new LatLng(locationObject.getLatitude(), locationObject.getLongitude());
if (mGmapsMarker == null) {
mGmap.addMarker(new MarkerOptions() mGmap.addMarker(new MarkerOptions()
.position(received) .position(received)
.title(mCurrentUser.getDisplayName())); .title(mCurrentUser.getDisplayName()));
} else {
mGmapsMarker.setPosition(received);
}
mGmap.moveCamera(CameraUpdateFactory.newLatLngZoom(received, 15.0f)); 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); 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)); mGmap.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultHome, 15.0f));
} }