I am using a single activity with multiple frgmetns where each holds a MapView in its fragment.
This is a reported bug, that i occurs on 4.0.4 android (probably on 4.0 also) but works properly on higher versions.
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027
Multiple maps v2 in TabActivity
When a new fragment is added both maps show. If a third fragment is added all tree maps are shown. I have tried applying the hideStupidMaps fix as discussed above but it provides no result( i have added calls to hide/show maps in onResume/onPause).
I have also added calls to hide the previous map before calling FragmentManager and its transaction but no result.
I have tried setting MapView visibility to INVISIBLE but also no result, the map previos map still shows, like no refresh is happening?
Is there a way to set zIndex to MapView? I know you can set z index when using MapFragment through GoogleOptions but i cant find an option to do that with MapView?
GoogleMapOptions options = new GoogleMapOptions();
options.zOrderOnTop(true);
fragmentMap = SupportMapFragment.newInstance(options);
I have managed to get it working. The problem was that i was actually calling hideStupidMaps after fragment transaction, and on 4.0.4 android it didnt have any effect while it worked on 4.1. I moved the call before the Fragment transaction and it worked. The only downfall is that for a moment the user can see the map disappear before Fragment animation starts.
I have also added a OnBackStackChangedListener where i would show the previously hidden map when returning via back button/action bar.
Hope it helps someone, and a piece of advise, avoid multiple maps in fragments if you can...
Related
My problem comes when I try to show() and hide() multiple map fragments. The map does not change using show()/hide(). the fragment can be removed or hidden but keeps in the screen(dirty).
Screen:
Here Related Issue
How can I correct this issue?
I faced a similar issue with overlapping maps belonging to different fragments.
These two thins helped me:
map:zOrderOnTop="false" on the small map.
I was using DialogFragments and calling dismiss() did the trick, but if you're using plain Fragments. you can try to remove the fragment with the FragmentManager.
What versions of Android? SDK? Maps?
Try to update: http://www.androidpolice.com/2013/07/09/google-maps-for-android-gets-updated-with-promised-interface-refresh-functionality-enhancements/
Might be a known issue: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&q=fragment&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal
I am not sure whether I should be using MapView or stick to using a MapFragment. My application is an app that finds the nearest set of places that are closest to you. I want to be able to add locations, display details of a marker when I press a marker and when the user moves along the map I want to be able to get the coordinates of the center of the map and display the nearest locations within a defined radius. Would I be at a disadvantage if I continue to use MapFragments or should I switch over to MapView while I still have the chance?
First of all, soon the MapView and Google Maps API V1 will stop being supported and won't receive any new updates. And soon all the support will go away.
Secondly, MapFragment may be a little bit less flexible right now, but the map presented, manipulated a looks much better. And I guess that it's functionality will improve with time.
So I would definitely continue to use MapFragments.
UPDATE:
As #Brian White pointed out in the comments, today there is a MapView in Google API V2, and you should use it when you want to embed a map in a fragment. That way you will avoid cascading fragments when you don't have to.
MapFragment
Use it if you want to add a map into Activity class (not fragment
because it will create a nested fragment and it´s a mess).
Use SupportMapFragment if you want to support just android versions
lower than v12.
MapView
Use it if you are going to add a map into a fragment. (you need to
update each lifecicle to MapView).
I looked and searched but don't see an answer but seen many commerical Android apps that can display Google Maps in fragments along with other fragments to display lists of items and other UI fragments.
I do not know if I need to use MapActivity for the whole app since I have a mix of fragments in addition to wanting to display google map in one of the fragments.
Its like this:
Fragment 1: displays Summary of User Settings
Fragment 2: displays the Google Map of user's location
Fragment 3: displays a list of items relevant to the user
I am using a Facebook-like menu UI to navigate among the Fragments. I like to know here is....
Can I mixed these Fragments together without using MapsActivity.
If I do need to use MapsActivity, how do work it with the other fragments that displays other UI elements that doesn't use MapsActivity's functions.
Thanks in advance.
The new Google Maps API V2 for Android has just been released, which includes a MapFragment class, take a look:
https://developers.google.com/maps/documentation/android/
Basically what i am trying to do is
Tab1 -> Organisation Map Fragment
Tab2 -> City Map
How should I go about doing this. I tried following some tutorials but it gives me the error "You are allowed to have single MapView in a MapViewActivity". Can some one please help me out
It's not possible to do this. As the message says, only one map per Activity.
As Joe and the error message says, you can only have one mapview in a single activity.
What you could do (if you still want to use tabs) is just not change the fragment when the tab changes, and instead reload the map with different data.
Google released the Map API Version 2. This finally allows to use a MapFragment and a SupportMapFragment. This allows adding Maps to ViewPagers and to Activities that do not extend MapActivity. It should also allow you to have multiple maps in one Activity
I have an activity that extends MapActivity and has two main elements, list view on the left and map on the right. I put a refresh button on the map and tried to :
map.setTraffic(true);
map.invalidate();
but nothing changed. the map did not refresh. I did searched a bit on google and understood that invalidate() should do the trick. I would like to avoid recreating the entire activity. Please help? Thank you.
You should not even need the invalidate(). This sample app toggles between regular and satellite tiles just by calling setSatellite() when you press the <S> key in the emulator.
Temporarily switch to setSatellite() instead of setTraffic(). If that works, then the problem is tied to the traffic tile set, which I have never tried.