How to add googleMap programmatically in a RelativeLayout?

1

I already have all the external settings performed, but my question is how to add googleMap programmatically on a RelativeLayout?

Here's my RelativeLayout

public class Page extends RelativeLayout {

private Context context;

public Page(Context context) {
  super(context);
  this.context = context;
  this.setLayoutParams(new RelativeLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

 // Eu preciso gerar o  googleMap aqui

  }
}
    
asked by anonymous 31.07.2014 / 21:09

1 answer

1

The code to have it added to your RelativeLayout would look like this:

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">


 <com.google.android.maps.MapView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map_view"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:clickable="true"
  android:enabled="true"
  android:apiKey="API-KEY-HERE" />
</RelativeLayout>

Maaas, do not just add this, you have a lot of settings to do ... I recommend reading the GMaps API documentation here: link

And if you want a tutorial on how to do this, you can follow this one: link

ps: To add GMaps to V2, you can follow this tutorial here: link

    
31.07.2014 / 21:24