On my Marker I added a setOnMarkerClickListener
. So here's my createMethod
protected void createMarker(String driversName, int totalPass, String busNum, double latitude, double longitude, String location) {
Marker marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(location)
.snippet("Driver's Name: " + driversName + "\nTotal Passenger: " + totalPass + "\nBus number: " + busNum));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker)
{
Toast.makeText(MainMapActivity.this, "hey!", Toast.LENGTH_SHORT).show();
dialogInfo();
return true;
}
});
}
dialogInfo()
public void dialogInfo() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Current Location: "+location);
builder.setMessage("Bus number: "+busNum+"\nDriver's name: "+name+"\nCurrent total passenger: "+totalPassenger)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
The values of the dialog is the same