Issue
I am an Android newbie. I am trying to get listView value from another activity and show the specific location according to that value. In this situation with only for first switch-case it works perfect, but when I add the second switch-case It is showing me the result of first and second. How can I improve this code to show only one result for each switch statement.
value1 = getIntent().getIntExtra("value1", 0);
value2 = getIntent().getIntExtra("value2", 0);
value3 = getIntent().getIntExtra("value3", 0);
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mMarker != null)
mMarker.remove();
latitude = location.getLatitude();
longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
MarkerOptions markerOptions = new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
mMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13));
switch (value1) {
case 0:
mBaniaLuca = mMap.addMarker(new MarkerOptions()
.position(BaniaLuca)
.title("BaniaLuca"));
mBaniaLuca.setTag(0);
break;
case 1:
mBiedronka = mMap.addMarker(new MarkerOptions()
.position(Biedronka)
.title("Biedronka"));
mBiedronka.setTag(0);
break;
}
switch (value2) {
case 0:
mTARITA = mMap.addMarker(new MarkerOptions()
.position(TARITA)
.title("Tarita"));
mTARITA.setTag(0);
break;
}
switch (value3) {
case 0:
mCocon = mMap.addMarker(new MarkerOptions()
.position(Cocon)
.title("Cocon"));
mCocon.setTag(0);
break;
}
Solution
Looks like each time you are going through the switch case, you are 'adding' a marker. Note the word 'adding'.
Prior to the switch case, statement, add code to remove all existing markers. If I understand your question right, this is the behavior you want.
Answered By - Venu G.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.