Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

getMapAsync for Android like in Google maps #2042

Closed

Description

@erf

Would it be an idea to load the mapview async as in google maps:

   mapFragment = new SupportMapFragment();
        mapFragment.getMapAsync(this);

   FragmentManager fragmentManager = getSupportFragmentManager();
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
   fragmentTransaction.replace(R.id.container, mapFragment);
   fragmentTransaction.commit();

In this way you could make the mapFragment static so you don't have to reinstanciate it each time you create the activity containing the map.

I have made an implementation of this.

Activity

  1. erf commented on Aug 12, 2015

    @erf
    ContributorAuthor

    I created a pull request for this:
    #2043

  2. erf commented on Aug 12, 2015

    @erf
    ContributorAuthor

    The problem i described in #2018 is back after i load the mapview this way

  3. added
    Android
    on Aug 13, 2015
  4. ljbade commented on Aug 14, 2015

    @ljbade
    Contributor

    I don't really understand what this does.

    It seems you are only changing the way the test app works?

    /cc @bleege

  5. erf commented on Aug 14, 2015

    @erf
    ContributorAuthor

    You probably would like to have MapView in a Fragment to reuse map functionality (like google do) and to add it programmatically you need to retrieve the MapView async from the MapFragment when it's added to the view or else it's null if you try to retrieve it just after you've created the MapFragment.

    But.. This causes another problem, i describe in #2018 that when i tried to switch from the MapActivity to some other Activity (after moved the maped) and back the app crashes..

  6. tobrun commented on Oct 7, 2015

    @tobrun
    Member

    @ljbade

    I would like to add why Google exposes this async get method:

    image

    This would crash because the MapFragment is not created/attached yet, for this reason an async callback was introduced.

    cc @bleege

  7. tobrun commented on Oct 7, 2015

    @tobrun
    Member

    Also here is an example how getMap can work, I used to implement GoogleMaps in this fashion before the async method was introduced and getMap was deprecated:

    image

  8. ljbade commented on Oct 7, 2015

    @ljbade
    Contributor

    @tobrun Interesting! Perhaps we should put this on 2.2.0 milestone as part of the refactor.

  9. added this to the android-v2.2.0 milestone on Oct 8, 2015
  10. modified the milestones: android-v2.3.0, on Dec 4, 2015
  11. tobrun commented on Jan 11, 2016

    @tobrun
    Member

    This will be implemented with #3145

  12. tobrun commented on Jan 29, 2016

    @tobrun
    Member

    This has landed with #3145. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidfeature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions