Google Map V2 Android Maps Extensions and Passing Data to Activities

Working with Android (JAVA) is awesome. I love how you can write a little code and see a huge change in a UI. I’ve been fiddling with Google Maps V2 and a simple app. I need to pass some data based on the marker clicked to the next activity. You can do this by making a complicated HashMap for example or you can do this easily by using an awesome library called Android Maps Extensions.

Using Android Studio, the simplest way to get this setup going is to create a new project and select the Google Maps premade activity. Give it a name and click Finish.

Next, add Android Maps Extensions to your build.gradle (module: app) file:

Most likely your build file dependencies will look like so:

After adding this to your build file, click the menu item Build and select Rebuild Project. This will get Android Map Extensions working in your project.

You now need to change a few things in code. Go to your activity_maps.xml and update  your map fragment with:

android:name=”com.androidmapsextensions.SupportMapFragment”

My activity_maps.xml looks like so:

Next in your MapsActivity.class update the following:

  • Change getMap(); (around line 49) to getExtendedMap();
  • Update your imports to use Android Map Extensions.
    • Hint: Easy way to do this is to delete all google map related imports and click ALT+ENTER on any Red highlighted items.

Next, open the google_maps_api.xml file found in the values folder and follow the directions to get an API key and enter your key in that file.

Plug in your device or open an emulator and RUN your project. If all went well, you will have Android Maps Extensions running. You can now use the great features offered such as:

  • Marker Clusters
  • GetData()
  • SetData(object) <<<< Which I need to pass data to new activity!
  • etc…

Find out more on the Android Maps Extensions website.

Download the complete sample project (zip 10mb) : MyGoogleMapProject