• Hello Map
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
    
            // Get a handle to the Map Fragment
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            LatLng sydney = new LatLng(-33.867, 151.206);
    
            map.setMyLocationEnabled(true);
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
    
            map.addMarker(new MarkerOptions()
                    .title("Sydney")
                    .snippet("The most populous city in Australia.")
                    .position(sydney));
        }
    }
  • Change the Map Type
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(-18.142, 178.431), 2));
    
            // Other supported types include: MAP_TYPE_NORMAL,
            // MAP_TYPE_TERRAIN, MAP_TYPE_HYBRID and MAP_TYPE_NONE
            map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        }
    }
  • Indoor Maps
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            // Some buildings have indoor maps. Center the camera over
            // the building, and a floor picker will automatically appear.
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(-33.86997, 151.2089), 18));
        }
    }
  • Custom Markers and Info windows
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(41.889, -87.622), 16));
    
            // You can customize the marker image using images bundled with
            // your app, or dynamically generated bitmaps. 
            map.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.house_flag))
                    .anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
                    .position(new LatLng(41.889, -87.622)));
        }
    }
  • Flat Markers
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            LatLng mapCenter = new LatLng(41.889, -87.622);
    
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13));
    
            // Flat markers will rotate when the map is rotated,
            // and change perspective when the map is tilted.
            map.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.direction_arrow))
                    .position(mapCenter)
                    .flat(true)
                    .rotation(245));
    
            CameraPosition cameraPosition = CameraPosition.builder()
                    .target(mapCenter)
                    .zoom(13)
                    .bearing(90)
                    .build();
            
            // Animate the change in camera view over 2 seconds
            map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
                    2000, null);
        }
    }
  • Polylines
    import com.google.android.gms.maps.*;
    import com.google.android.gms.maps.model.*;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class MapPane extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
            GoogleMap map = ((MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
    
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(-18.142, 178.431), 2));
    
            // Polylines are useful for marking paths and routes on the map.
            map.addPolyline(new PolylineOptions().geodesic(true)
                    .add(new LatLng(-33.866, 151.195))  // Sydney
                    .add(new LatLng(-18.142, 178.431))  // Fiji
                    .add(new LatLng(21.291, -157.821))  // Hawaii
                    .add(new LatLng(37.423, -122.091))  // Mountain View
            );
        }
    }