I'm currently trying to have 2 maps v2 in different tabs of a TabActivity using MapView objects. The problem arises in the following scenario:
tab1 with a map is displayed
go to tab2 in order to display another map
in this second tab looks like the map image from first tab is overlapping the new map. See the following picture:
On the right you can see how the first map is still displayed on top of it. The touch events are going to the new map but that doesn't really help. I spent a lot of time trying to convert our app to use fragments and run into other types of issues. One of them being http://code.google.com/p/android/issues/detail?id=40035 so that's not a good option either.
So far I haven't been able to find any workaround. To easily try various changes I wrote a simple application and made it available here: https://github.com/cristizmf/TestMapsV2. It needs only the right location for maps library project and a good maps key in manifest.
Any ideas would be greatly appreciated.
Later edit: I've logged an issue for this: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369
We are having the exact same problem. I suspect this is caused by the fact that the new maps uses OpenGL - possibly android cant deal with having two OpenGL widgets in the view hierarchy at the same time even though one is hidden.
The only way we worked around this was to actually remove the mapview when leaving a tab, then construct a new one and add it back in when going back into the tab. This ensures that there are never two maps constructed at once.
Nasty, but it worked.
I ran into the same issue a few days ago and was pulling my hair out over what to do.
Originally I had my app set up with "Tabs the Fragment way" as seen here to avoid the deprecated TabActivity, and used this hack to allow me to incorporate Maps v1 in with the Fragments. It basically just masks an Activity as a Fragment.
But then switched to TabActivity further down the track for simplicity / it was better suited for the whole app.
But now obviously this 2x Maps v2 fragment problem has become an issue..
So I have reverted back to "Tabs with Fragments" and just have the "hack setup" as mentioned above for each tab, which allows to have an Activity for each tab, AND having more than one Maps v2 displaying for each Tab. I haven't gone into too much depth with it, but it seems to be doing the job atm, with having just thrown some code together to test it out..
Don't know if you're still having an issue with this / this obviously isn't the most correct solution, but just thought I'd share my two cents incase you still needed it.
Cheers.
Related
I'm an averagely experienced Android programmer.
I'm currently working on an app that includes the google maps API and among the activities there are two views that include a map fragment. Now I want someone to be able to navigate on one of those views, called mapActivtiy. It basicly consists of a map, that's all. After choosing a location in another view, I want the map to display the direction from the users position (which I already know) and the target's location.
Now, in iOS I'd just throw in the MKDirections stuff from the MapKit framework, but I seem to be unable to find something equivalent for android. Is there any API or something for wayfinding and navigation on the map? If so, where to look for it?
Just to clearify this: I know I can call the google navigation app from my app, but I don't (really) want to do that, I'd prefer staying within my context. Using the navigation app is more of a last resort.
Does anyone have a smart adivce for me?
Any idea would be much appreciated!
I have this application I want to upgrade from Google maps API 1.0 to the 2.0 especially for some performances issues.
Now, the application was designed (not by me) with a single Map defined in the unique main activity and use through the different fragments (included in the fragments as a View).
I am reading about the new api and have doubts:
1) Is it good to have 2 fragments on the same screen, one just for the map and the other one for other UI? This way i can create the effect of expanding/hiding almost completely the map with is such in fashion right now?
2) Have you knowledge about some guidelines to upgrade the API? I run on content about how to create with Api 2.0 but not to upgrade: rules, errors, guidelines?
Thank you a lot.
Edit: As always, I am working on it right now and I will post my solution/choice when I am done.
1) Is it good to have 2 fragments on the same screen, one just for the
map and the other one for other UI? This way i can create the effect
of expanding/hiding almost completely the map with is such in fashion
right now?
Yes it is expected within the framework to have multiple fragments on the screen and is a large part of the reason they exist.
2) Have you knowledge about some guidelines to upgrade the API? I run
on content about how to create with Api 2.0 but not to upgrade: rules,
errors, guidelines?
The Getting Started section should help you somewhat on this transition. If there is something specific you are looking for such as optimizing memory during the placement of markers on the map it would be best to search for that as needed.
1) Is it good to have 2 fragments on the same screen, one just for the map and the other one for other UI?
Depends on what data you want to put on one screen. It is often a good idea to have most of the UI-related logic inside Fragments instead of Activities, because they can be arranged differently on phones and tablets.
This way i can create the effect of expanding/hiding almost completely the map with is such in fashion right now?
Animating might be problematic. See Issue 4659 and Issue 4639.
2) Have you knowledge about some guidelines to upgrade the API? I run on content about how to create with Api 2.0 but not to upgrade: rules, errors, guidelines?
IMHO the best way is to forget (delete) all the code related to v1 and start from scratch, following official documentation.
I searched the docs of the new Google Android Map API v2, but didn't find anything about it. Before v2 we (officially) couldn't properly display more than one map per application (process). I assume that with MapFragment implementation it's no longer an issue. I also know, that Fragments can be self-contained since API 17. And, last but not least, there is compatibility package, which makes it possible to port it all back to at least API 8 (in API 7, there's no OpenGL 2.0 so the maps wouldn't work afaik).
Sa I have all the ingredients to port my app to Maps API v2 and implement the following scenario: ViewPager contains Fragments and each of them contains a MapFragment.
But should I do it? I mean, would I face performance issues if I had e.g. 20 Fragments containing MapFragments in a ViewPager?
If you found anything that addresses my concern in the docs or somewhere else, please tell me.
EDIT: Example usage: Let's imagine a screen containing informations about some specific item - place, event, article. Also let's imagine that, among other informations, it must contain a map to be fully functional. But I would like the user to be able to swipe to another item if he wants. Each item has its own map.
Side note: I know that I can implement one map outside the ViewPager and just update it based on the currently displayed item, but it's not what I'm looking for - it's not user-centered design.
Possible solution (but not checked yet). ViewPager only keeps a few (default - 3) Fragments in it's cache and recreates them when they're about to show up, so there won't be much memory overhead as only a few MapFragments are needed. The performance problem may be the MapFragment inflation which is quite heavy, I believe - but that can be solved with recycling of MapFragments.
So why won't I implement it if I believe it will work nice? There's another problem which makes it impossible to move MapFragments without the app look like it's broken. See this.
You could easily test it but my guess is that it would very much depend on the phone as Maps still is fairly heavy to run.
That said I'd never recommend this kind of user navigation. A map can already be swiped at so why would you add ViewPager swipe as well? This would make a very confusing user experience. If you want to switch between different views/point of interests you should add buttons (overflow menu buttons preferred as in the navigation app) or something similar that helps the user navigate around.
Yes, you definitely would run into performance issues because ViewPager doesn't employ view recycling by default; you can even bloat it with ImageViews let alone MapFragments.
As far as caching and recreating fragments in ViewPager - there's a HorizontalListView lib that'd probably save you the effort as it does support view recycling.
I have been researching this for a while now. I actually have 2 working applications that implement a map in a fragment. Each application uses a different approach. Wondering which is better if any. I am also wondering if i am just behind on this and maybe there is a better way that i have not found yet.
The 2 approaches.
One uses LocalActivityManager which is depreciated.
The other approach is detailed here using a Exchanger to coordinate between Activity and Map
The first method has the drawback of already being depreciated.
I thought i saw a problem with the second method but i am unable to find it again.
Is there any benefit to one method or the other. Or is there something else that i should be looking into?
Thankyou.
Look at this library (android-support-v4-googlemaps)
A port of the Android Compatibility package which makes FragmentActivity extend MapActivity. This is a hack to make it possible to use a MapView in a Fragment.
Moreover i use it instead of Compatibility package to build ActionBarSherlock - so i have map + fragments + action bar.
In my app mapview works great on some phones and very poorly on other phones. it seems to be a RAM issue, ie. phones with a lot of ram and a lot of heap work great and smoothly, phones without work very poorly.
I am recycling bitmaps and clearing things, but it doesn't seem to help. During app development it seemed kind of random when some phones would have issues with the mapview, but now it seems very consistent.
Basically on phones that don't work well, the mapview tiles load slowly, other parts of the app function very slowly, and the google map search does not give search suggestions or update the map with the address searched for.
On phones that do work, mapview tiles load quickly, other parts of the app function very quickly, the google map search gives search suggestions and the map updates exactly as desired.
what causes this and how would I improve it? (it is standard mapview code)
I saw a similar question about "android mapview is slow", basically was my problem, but the solution was irrelevant for me, how do apps that use mapview account for this?
Have you looked at this bug report (and related workarounds):
http://code.google.com/p/android/issues/detail?id=2181
Well you don't actually supply any code, but have you considered that the problem might be related to something else than the mapview? Or have you considered that perhaps you could improve the performance in other ways? There isn't much you can do with the mapview itself to improve performance.
You could investigate if the mapview slow without overlays. I recently found out my implementation of itemizedoverlay was bad because I was adding items and calling populate every time I added a new item instead of calling populate when I was done adding items. This didn't give any problems before (without tab layout) but with the tabs it worked really slow.
Another thing you could try was to go away from tabs with activities (I assume you do this now) and use tabs with fragments instead. And yes this is possible with mapview just dl one of the many fragmentmapactivities or make your own fragmentmapactivity.
One thing that will defiantly improve your performance will be setting the mapView as the top view of your activity.
MapView myMap = createMapView();
setContentView(myMap);
And I will even suggest you to do this within a new activity. Of course if you can.