Code example for SupportMapFragment

Methods: getMap, onActivityCreated

0
        destination = new LatLng(37.45, -122.2);
    } 
 
    @Override 
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setUpMapIfNeeded(); 
    } 
 
    private void setUpMapIfNeeded() { 
        PolygonOptions rectOptions = new PolygonOptions()
                .add(new LatLng(37.35, -122.0),
                        new LatLng(37.45, -122.0),
                        new LatLng(37.45, -122.2));
        if (map == null) {
            map = this.getMap();
            if (map != null) {
                map.addMarker(new MarkerOptions().position(new LatLng(37.35, -122.0)).title("Hello World"));
                map.addMarker(new MarkerOptions().position(new LatLng(37.45, -122.0)).title("Hello World"));
                map.addMarker(new MarkerOptions().position(new LatLng(37.45, -122.2)).title("Hello World"));
                map.addPolygon(rectOptions);