Mapview and Fragment
I've seen some topics some months ago, about the fact that using (Google)MapView inside a Fragment was a bit tricky/impossible. I would like to know if atm (June) there is a workaround ? My application (Android 3.0) is essentially working with the Fragment system and I need to display a map in one of these fragment开发者_如何学JAVAs.
Currently I only know of one solution. I stumbled across this when I ran into the same problem. https://github.com/petedoyle/android-support-v4-googlemaps.
EDIT
Here is a newer fork based off r9 https://github.com/rfc1459/android-support-v4-googlemaps
You can build it via eclipse or download a compiled version here https://github.com/rickbarrette/android-support-v4-googlemaps/downloads
There is another question already. Basically the workaround is to create an Activity manager and a TabHost and create a single tab containing a MapActivity. In this way you can load a separate MapActivity inside a Fragment.
For more information see the sample project provided by the original answerer.
Since this question was posted, Google have now very recently (start of December '12) published the V2 Android Maps API. As well as other features, it is designed to work with Fragment
s and does away with the MapActivity
nonsense.
https://developers.google.com/maps/documentation/android/
So it looks like we can now happily use maps in Fragments without the need for hacks.
The only slight disadvantage I've come across so far after initially playing with this new API is that older devices seem to require the user to install Google Play Services first, which may make some users whinge a bit. As they do.
精彩评论