How to add Googlemap programmatically to a Relativelayout?

Asked

Viewed 114 times

1

I already have all external settings performed, but my question is how to add Googlemap programmatically in a Relativelayout?

Here is 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

  }
}
  • For which map version would this implementation be, google maps v1 or v2?

  • google maps v2...

1 answer

1

The code to have it added in 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, it’s not just add this, it has a number of settings to make it...I recommend reading the Gmaps API documentation here: https://developers.google.com/maps/? hl=en

And if you want a tutorial on how to do this, you can follow this one: http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html

ps: To add Gmaps to V2, you can follow this tutorial here: http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

  • My google maps is already configured googleConsole, I already have key and everything you need. What I need is to add inside my class that extends Relativelayout without using xml

  • And why not use xml? And you’ve read their documentation?

  • I am developing a Template application, which will generate screens from external JSON and need my class to be programmatic and without xml

  • Dante, isn’t this mapView the V1? I need the v2.

  • @Igorronner, man, I found a link here that can be very interesting for you, check it out: http://www.basic4ppc.com/android/forum/threads/google-maps-android-v2-tutorial.24415/

  • @Igorronner, I updated my reply with a well explained link to V2

  • 1

    Thanks Dante, but I ended up making a slight change so I could load straight from my main Activity and it worked

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.