title: How I can show Google Maps V2 into a custom dialog android
body: <p>Hello my name is Hernan so and I am a Android Developer. I make this question because I need insert a google map into a custom dialog I already have my dialog working ok but when I am adding the google map it throws an error in code. This is my code.</p>
  
  <p>Java Code:</p>
  
  <pre><code>package com.sigetdriver.view.popup;
  
  import android.app.Dialog;
  import android.content.Context;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.view.WindowManager.LayoutParams;
  import android.widget.Button;
  import android.widget.Toast;
  
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.MapFragment;
  import com.sigetdriver.R;
  
  public class InsertarDestinoPopup {
  
      private GoogleMap googleMap;
      private Context context;
      public Dialog dialog;
      private Button btnCerrar;
  
      public void dialog(Context _context) {
  
          context = _context;
          dialog = new Dialog(_context);
          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setContentView(R.layout.popup_destino);
          dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  
          try {
              // Loading map
              initilizeMap();
              pintarMapa();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          btnCerrar = (Button) dialog.findViewById(R.id.btnCerrar);
          btnCerrar.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  dialog.dismiss();
              }
          });
  
          dialog.show();      
  
      }
  
      /**
       * function to load map. If map is not created it will create it for you
       * */
      private void initilizeMap() {
          if (googleMap == null) {
              googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                      R.id.map)).getMap(); // *******ERROR HERE******* 
  
              // check if map is created successfully or not
              if (googleMap == null) {
                  Toast.makeText(context,
                          "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                          .show();
              }
          }
      }
  
      private void pintarMapa() {
  
          googleMap.setMyLocationEnabled(true); // false to disable
  
      }
  
  }
  </code></pre>
  
  <p>XML Code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
      &lt;fragment
          android:id="@+id/map"
          android:name="com.google.android.gms.maps.MapFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
      &lt;Button
          android:id="@+id/btnCerrar"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Cerrar" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I dont know if it is the best way to make a dialog or showing a map into dialog, please I need solve this thanks in advance.</p>
  
  <p>Hernan </p>