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

getMapAsync for Android like in Google maps #2042

Closed
erf opened this issue Aug 12, 2015 · 9 comments
Closed

getMapAsync for Android like in Google maps #2042

erf opened this issue Aug 12, 2015 · 9 comments
Labels
Android Mapbox Maps SDK for Android feature

Comments

@erf
Copy link
Contributor

erf commented Aug 12, 2015

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.

@erf
Copy link
Contributor Author

erf commented Aug 12, 2015

I created a pull request for this:
#2043

@erf
Copy link
Contributor Author

erf commented Aug 12, 2015

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

@ljbade ljbade added feature Android Mapbox Maps SDK for Android labels Aug 13, 2015
@ljbade
Copy link
Contributor

ljbade commented Aug 14, 2015

I don't really understand what this does.

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

/cc @bleege

@erf
Copy link
Contributor Author

erf commented Aug 14, 2015

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..

@tobrun
Copy link
Member

tobrun commented Oct 7, 2015

@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

@tobrun
Copy link
Member

tobrun commented Oct 7, 2015

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

@ljbade
Copy link
Contributor

ljbade commented Oct 7, 2015

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

@tobrun
Copy link
Member

tobrun commented Jan 11, 2016

This will be implemented with #3145

@bleege bleege removed this from the android-v3.1.0 milestone Jan 20, 2016
@bleege bleege modified the milestones: android-v4.0.0, android-v3.1.0 Jan 20, 2016
@tobrun
Copy link
Member

tobrun commented Jan 29, 2016

This has landed with #3145. Closing

@tobrun tobrun closed this as completed Jan 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android feature
Projects
None yet
Development

No branches or pull requests

4 participants