Tsunami
Tsunami

Reputation: 1

Android: How to create a map by java code rather than by xml in google map api v2?

In my android project, I would like to create a Google Map using java code rather than useing xml, how should I do?

Upvotes: 0

Views: 574

Answers (1)

GrIsHu
GrIsHu

Reputation: 23638

You can add a Map using MapFragment to an Activity in code. To do this, create a new MapFragment instance, and then call FragmentTransaction.add() to add the Fragment to the current Activity.

   mMapFragment = MapFragment.newInstance();
   FragmentTransaction fragmentTransaction =getFragmentManager().beginTransaction();
   fragmentTransaction.add(R.id.my_container, mMapFragment);
   fragmentTransaction.commit();

For more details check out the GoogleMaps, you will have more idea of implementing the maps.

Upvotes: 2

Related Questions