I have this application where I show markers on google maps for pharmacies nearby. When I click on marker I want the marker to change the colour. When I click on some other marker, it should change the previous marker's colour to default and will change new marker's colour. This is working randomly, I mean sometimes marker colour is getting changed and sometimes it stays the default color.
public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in user's location // User's location is taken from the postal code entered mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { if(lastClicked != null){ lastClicked.setIcon(BitmapDescriptorFactory.defaultMarker()); } marker.setIcon(getMarkerIcon(getResources().getColor(R.color.app_color))); lastClicked=marker; return false; } }); }
NOTE: I added debugger in every line to see what part of code does not run, and it is strange that when debugger come to this line
marker.setIcon(getMarkerIcon(getResources().getColor(R.color.app_color)));
it is getting compiled and yet sometimes it does not change the color of the marker.
https://stackoverflow.com/questions/65895430/marker-sometimes-change-colour-on-click-and-sometimes-it-does-not January 26, 2021 at 11:17AM
没有评论:
发表评论