Android OS: Add GoogleMap as fragment
- Joel Lipman
- AndroidOS
- Hits: 21212
- Android Studio (Beta) 0.8.9
- Android Google Maps v2
What?
A sequel to my article "Basic Android App using Google Maps and Current Location", this article suggests how to add Map as a sub activity. Note that this article is based on a new blank project which does not include code from the previous example but you can still build this over the previous example (as I did).
Why?
The previous article meant that the Google map was your main activity and any other activity would be a sub-activity; returning to the map activity would restart the app as a menu item, it would need to launch a new intent... I wanted to change my previous example so that the homepage of the app (the starting page) will simply display a button to the map (in case of offline mode or incompatibility with the device).
How?
In this example, I'm going to add the map as a fragment. This is the most rudimentary example (display map, move camera and display marker) and can be run from any other activity: