0
I’ve researched and tried some alternatives, but I haven’t 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 "location a". B) 2 button results in displaying the map only with "location b".
*What I could: link the buttons to the map and display "all" markers. Not desired.
Follow 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);
}
}
I understood, but how I link to the 2 If that are in the code final part?
– LUIZ
I don’t understand. What do you mean "how do I link to 2 If"?
– ramaral
I want to link the status, visible or not visible, to the button that was selected on the previous screen of the app. And each "If" checks whether the button 1 or 2 has been pressed by the user.
– LUIZ
Can’t build the
if
? If you know where it isLocalA.visible(true)
andLocalB.visible(false)
replace withmarkerA.visible(true)
andmarkerB.visible(false)
.– ramaral
I don’t know how to implement the "If" condition check: if(ENTER BY BOOT 1) or if(ENTER BY BOOT 2)
– LUIZ
You should create another question and add more details so we can understand exactly what you want to do. It seems to me (I’m not sure) that what you need is to implement the method
onClick()
of each of the buttons.– ramaral
Let’s go continue this discussion in chat.
– LUIZ