'RecyclerView items to different coordinates on Google Map
I connected RecyclerView with MapFragment (click on any RecyclerView item opens a GoogleMap). Data displayed in RecyclerView is coming from Firebase.
Currently map displays multiple markers that represent different locations (hardcoded lat and lng values inside onMapReady() in MapActivity).
I want a map to zoom to specific marker/location (lat&lng) after user clicks RecyclerView item representing that location.
I didn't have any success doing that following some of the answers here (Passing coordinates to Google Maps in android & Recyclerview data to marker in Google Maps).
I need to pass data and iterate if I'm getting this right.. I can't get passing data with intent to work. Any help would be appreciated
Item click from MainActivity.java:
@Override
public void onItemClick(int position) {
Intent intent = new Intent(this, MapActivity.class);
startActivity(intent);
}
}
onMapReady in MapActivity.java:
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
mMap = googleMap;
// example marker
LatLng mylocation = new LatLng(45.853060,15.949983);
mMap.addMarker(new MarkerOptions().position(mylocation).title("My Location")
.icon(bitmapDescriptorFromVector(getApplicationContext(),R.drawable.ic_baseline_location_on_24)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mylocation,10f));
}
Rest of the code can be found here: https://pastebin.com/cCKGKFVV
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
