Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:17:00+00:00 2026-06-15T19:17:00+00:00

Background I have successfuflly added the new map api v2.0 to a ViewPager and

  • 0

Background

I have successfuflly added the new map api v2.0 to a ViewPager and the map loads fine. I am using the FragmentViewPager. I run into trouble however when trying to add markers as I cannot get the Fragment by tag as the ViewPager I am using is from the compatibility library and defined in XML, and this “hides” the tag from me.

The Question

How can I load the new Map v2 with markers SupportMapFragment into a ViewPager that uses a FragmentPagerAdapter.

My Attempt

So in my nievety I thought could create an elegant solution by extending the SupportMapFragment into a new class that does the following:

  1. Add a new constructor that takes GoogleMapOptions and List<MarkerOptions> . This effectively calls the existing constructor that just takes GoogleMapsOptions and then store my list of markers inside a private property of the new class.
  2. Override GetMap() – check if it is null and if it is not add the markers to the map that we loaded earlier on to the map and finally return it.

My thoughts were that my extension could be highly reusable and abstracts anything map related to one place and allows my activities to create the new MapFragment by newInstance(myGoogleMapOptions, myMarkers).

Ok so the issue. Part 1 seems to work fine however during debugging I cannot get the overridden GetMap() method to be called. In fact I have tried overriding most of the usual methods that fragments have and none of them get called. Is there something weird going on with the SupportMapFragmemt, I tried to find the source for it to no avail to check for myself.

Update

I realised why I wasn’t getting my overridden methods called. It was because I was returning the standard SupportMapFragment rather than MyMapFragment. That said I cannot call super from a static method and I cannot cast from a base class to a derived class without exception.

Edit
Here is the class

public class MyMapFragment extends SupportMapFragment {

    private static List<MarkerOptions> mMarkers;

    public static SupportMapFragment newInstance(GoogleMapOptions options, List<MarkerOptions> markers)
    {
        SupportMapFragment fragment = newInstance(options);

        mMarkers = markers;

        return fragment;

    }

            //have tried Overriding several methods including getMap()...

    @Override
    public void onResume ()
    {
        GoogleMap mMap = super.getMap();
        //add the markers
        if(mMap != null)
        {
            for(MarkerOptions marker : mMarkers)
            {
                mMap.addMarker(marker);
            }
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:17:01+00:00Added an answer on June 15, 2026 at 7:17 pm

    Just tried like this and it works.

    public class MyMapFragment extends SupportMapFragment {
    
        private List<MarkerOptions> mMarkers;
    
        public static MyMapFragment create(GoogleMapOptions options, ArrayList<MarkerOptions> markers) {
            MyMapFragment fragment = new MyMapFragment();
    
            Bundle args = new Bundle();
            args.putParcelable("MapOptions", options); //obtained by decompiling google-play-services.jar
            args.putParcelableArrayList("markers", markers);
            fragment.setArguments(args);
    
            return fragment;
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // Hacky and ugly but it works
            ArrayList<Parcelable> list = getArguments().getParcelableArrayList("markers");
            mMarkers = new ArrayList<MarkerOptions>(list.size());
            for (Parcelable parcelable : list) {
                mMarkers.add((MarkerOptions) parcelable);
            }
        }
    
        @Override
        public void onResume() {
            super.onResume();
            GoogleMap mMap = super.getMap();
            //add the markers
            if (mMap != null) {
                for (MarkerOptions marker : mMarkers) {
                    mMap.addMarker(marker);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully implemented this method of using the Win32 API to set the
I'm new to Prism, but I have successfully built several WPF/Mvvm-Light applications. I'm using
I am very new to asp.net mvc. I also have no enough background in
I'm having trouble getting objects back out of SimpleDB using the simpleJPA persistance API.
Ubuntu 11.10, Python 2.6. Background: I have an existing Python app that is using
Background: I have an MVC based polaroid object. The model keeps the photo's metadata,
Background I have an array of objects (Users) defined and set as follows: //
Background I have two lists, the first is items which contains around 250 tuples,
Background I have a function that takes a config object as an argument. Within
Background : I have a few different threads which each need to write to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.