This Activity code will provide basic functionality for including a Google Map using a SupportMapFragment.

The Google Maps V2 API includes an all-new way to load maps.

Activities now have to implement the OnMapReadyCallBack interface, which comes with a onMapReady() method override that is executed every time we run SupportMapFragment.getMapAsync(OnMapReadyCallback); and the call is successfully completed.
Maps use Markers, Polygons and PolyLines to show interactive information to the user.

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(; mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney, Australia, and move the camera. LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } }
Code language: PHP (php)

Notice that the code above inflates a layout, which has a SupportMapFragment nested inside the container Layout, defined with an ID of The layout file is shown below:


<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment xmlns:android="" xmlns:tools="" xmlns:map="" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context="" android:name=""/> </LinearLayout>
Code language: HTML, XML (xml)

This is the Basic Google Map integration

Leave a Reply

Your email address will not be published. Required fields are marked *