From a fragment (a list of cities), by clicking on an item from the list in it (fragment), an Activity opens with a fragment of Google Maps. I can not figure out how to transfer the coordinates to a fragment of googleMaps. The documentation says how to set coordinates with a marker, but it doesn’t say how to transfer them from an array.

Here is the array code for the fragment.

class MosOblClass { private String nameOblMos; private int imageId; private String coordinator; static final MosOblClass[] mosObl = { new MosOblClass("Рузское водохранилище", "geo:36.051622,122.310075", R.drawable.flat_19), new MosOblClass("Можайское водохранилище", "geo:56.051622 37.310075",R.drawable.flat_12), new MosOblClass("Озеро Морозово", "geo:56.051622 37.310075", R.drawable.flat_13), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_10), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_11), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_12), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_13), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_14), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_15), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_17), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_18), new MosOblClass("Другое водохранилище", "geo:56.051622 37.310075", R.drawable.flat_19), }; private MosOblClass(String nameOblMos,String coordinator, int imageId) { this.nameOblMos = nameOblMos; this.imageId = imageId; this.coordinator = coordinator; } public String getName() { return nameOblMos; } public String getCoordinator() { return coordinator; } public int getImageResourceId() {return imageId; } } 

GoogleMaps fragment class

 public class GameActivity extends AppCompatActivity implements OnMapReadyCallback { SupportMapFragment mapFragment; GoogleMap map; final String TAG = "myLogs"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync((OnMapReadyCallback) this); setTitle(getIntent().getStringExtra("name")); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @Override public void onMapReady(GoogleMap map) { LatLng mesto = new LatLng(0,0); map.addMarker(new MarkerOptions().position(mesto).title("name")); map.moveCamera(CameraUpdateFactory.newLatLng(mesto)); } } 

Here is a fragment from where you need to transfer

 public class MosOblFragment extends Fragment { RecyclerAdapter.Listener mListener; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final RecyclerView moscowRecycler = (RecyclerView)inflater.inflate(R.layout.fragment_oblasty, container, false); final String[] oblastyName = new String[mosObl.length]; for (int i = 0; i < oblastyName.length; i++){ oblastyName[i] = mosObl[i].getName(); } final String[] oblastyGeo = new String[mosObl.length]; for (int i = 0; i < oblastyGeo.length; i++){ oblastyGeo[i] = mosObl[i].getCoordinator(); } int[]moscowImage = new int[mosObl.length]; for (int i = 0; i < moscowImage.length; i++) { moscowImage[i] = mosObl[i].getImageResourceId(); } RecyclerAdapter adapter = new RecyclerAdapter(oblastyName,oblastyGeo, moscowImage); moscowRecycler.setAdapter(adapter); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); moscowRecycler.setLayoutManager(layoutManager); adapter.setListener(new RecyclerAdapter.Listener() { public void onClick(int position) { /* Intent intent = new Intent(getActivity(), GameActivity.class); intent.putExtra("name", mosObl[position].getName()); intent.putExtra("new", mosObl[position].getCoordinator()); intent.putExtra(Intent.EXTRA_TEXT, "Text"); //intent.putExtra(OblastyMoscowActivity.EXTRA_OBLASTYMO, position); getActivity().startActivity(intent); */ } }); return moscowRecycler; } } 
  • Marked by you earlier tags almost deprived of the question and the chance that he would be noticed. Moreover, the android-studio tag does not apply to the question at all. Try to format the code normally (by selecting and pressing curly brackets in the editor). And try to localize the problem. It seems your question is not about maps at all, but about the transfer of custom object classes from activations to the fragment - Yuriy Spb
  • Thanks for the tip. I'll try to write a more specific question - Dmitry Zenin
  • To transfer data between the Activity and the fragment, you need to use the additions for the fragments, and get them from the Bundle savedInstanceState - Andrey Lehan

0