I researched and tried some alternatives, but I have not been successful so far.
* I would like to display the markers according to the button pressed on the main screen. For example: A) button 1 results in displaying the map only with "local a". B) button 2 results in displaying the map only with "local b".
* What I did: link the buttons to the map and display "all" the markers. Unwanted.
Here is the short code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap
;
// Criando dois locais (A e B :
LatLng localA = new LatLng(-5.8702316, -35.2079593);
LatLng localB = new LatLng(-5.8843777, -35.1747881);
//Inserindo pinos (markers) baseado nos locais criados:
mMap.addMarker(new MarkerOptions().position(localA)
.title("Aqui é o local A")//título
.snippet("Confirme por Tel.: 5555-5555")//subtítulo
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))//cor
.visible(true));
mMap.addMarker(new MarkerOptions().position(localB)
.title("Aqui é o local B”)//título
.snippet("Confirme por Tel.: 5555-5555")//subtítulo
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))//cor
.visible(true));
if(ENTRAR PELO BOTAO 1)
Exibir o “Local A” e ocultar o “Local B”:
LocalA.visible(true)
LocalB.visible(false)
if(ENTRAR PELO BOTAO 2)
Exibir o “Local B” e ocultar o “Local A”:
LocalA.visible(false)
LocalB.visible(true)
//Local padrão para abertura do mapa: mMap.animateCamera(CameraUpdateFactory.newLatLngZoom((localA), 12));//zoo de 12 no local A
mMap.setMyLocationEnabled(true);
}
}