Я внедряю активность Google Maps в свое приложение, и я хотел бы предоставить этим картам активность по адресу.Эти адреса хранятся в Firestore RecyclerView, и я бы хотел, чтобы на карте отображался адрес, когда пользователь щелкает по одной из строк Firestore RecyclerView ...
Вот держатель
public class RecyclerViewHolder1 extends RecyclerView.ViewHolder {
public TextView mnomeEsercente, mindirizzoEsercente;
public RecyclerViewHolder1(@NonNull View itemView) {
super(itemView);
mnomeEsercente = itemView.findViewById(R.id.roWnomeEsercente);
mindirizzoEsercente = itemView.findViewById(R.id.roWindirizzoEsercente);
}
}
Вот адаптер
public class RecyclerViewAdapter1 extends RecyclerView.Adapter<RecyclerViewHolder1> {
Esercenti esercenti;
ArrayList<User1> user1ArrayList;
public RecyclerViewAdapter1(Esercenti esercenti, ArrayList<User1> user1ArrayList) {
this.esercenti = esercenti;
this.user1ArrayList = user1ArrayList;
}
@NonNull
@Override
public RecyclerViewHolder1 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(esercenti.getBaseContext());
View view = layoutInflater.inflate(R.layout.single_rowesercenti, parent, false);
return new RecyclerViewHolder1(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerViewHolder1 holder, int position) {
holder.mnomeEsercente.setText(user1ArrayList.get(position).getNomeEsercente());
holder.mindirizzoEsercente.setText(user1ArrayList.get(position).getIndirizzoEsercente());
}
@Override
public int getItemCount() {
return user1ArrayList.size();
}
}
А есть действие
public class Esercenti extends FragmentActivity implements OnMapReadyCallback {
FirebaseFirestore db1;
RecyclerView mRecyclerViewEsercenti;
ArrayList<User1> user1ArrayList;
GoogleMap map;
RecyclerViewAdapter1 adapter1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_esercenti);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
user1ArrayList = new ArrayList<>();
setUpRecyclerView();
setUpFirebase();
loadDataFromFirebase();
}
private void loadDataFromFirebase() {
if (user1ArrayList.size() > 0)
user1ArrayList.clear();
db1.collection("esercenti").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
for (DocumentSnapshot querySnapshot : task.getResult()) {
User1 user1 = new User1(querySnapshot.getString("nomeEsercente"), querySnapshot.getString("indirizzoEsercente"));
user1ArrayList.add(user1);
}
adapter1 = new RecyclerViewAdapter1(Esercenti.this, user1ArrayList);
mRecyclerViewEsercenti.setAdapter(adapter1);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Esercenti.this, "Problema di caricamento,controlla la tua connessione!", Toast.LENGTH_SHORT).show();
}
});
}
private void setUpFirebase() {
db1 = FirebaseFirestore.getInstance();
}
private void setUpRecyclerView() {
mRecyclerViewEsercenti = findViewById(R.id.RecyclerViewEsercenti);
mRecyclerViewEsercenti.setHasFixedSize(true);
mRecyclerViewEsercenti.setLayoutManager(new LinearLayoutManager(this));
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
LatLng base = new LatLng(0, 0);
map.addMarker(new MarkerOptions().position(base).title("Sede AirBc"));
map.animateCamera(CameraUpdateFactory.newLatLng(base));
map.animateCamera(CameraUpdateFactory.zoomIn());
}
}
Как это сделать?Заранее спасибо!