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/
Related
I've built my app layout and it's all looking good to me about where my things will go. I'll put a screenshot of the one fragment in which I want to place a small google map API.
I want the google map in the button which says "MAP". I'm fairly new to android development and would really appreciate it if someone could help me out with this and/or send me links to the videos that talk about exactly what I want because everything that I've tried searching for is either not necessary or not what I want.
Here's my page;
I want to add a map to the 'MAP' button that is clickable and will take me to google maps or if that's not considered 'API', I want it to become full screen. I'd prefer if it takes me to google maps though.
Thanks a lot for the help!
The basic steps for adding a map are:
You need to set up your API key and Gradle dependencies.
https://developers.google.com/maps/documentation/android-sdk/config
Add a Fragment object to the Activity that will handle the map. The easiest way to do this is to add a element to the layout file for the Activity.
Implement the OnMapReadyCallback interface and use the onMapReady(GoogleMap) callback method to get a handle to the GoogleMap object. The GoogleMap object is the internal representation of the map itself. To set the view options for a map, you modify its GoogleMap object.
Call getMapAsync() on the fragment to register the callback.
Please go through this link to get you started: https://developers.google.com/maps/documentation/android-sdk/map
I don't have much experience in Android and I am facing an issue related to Google map and AutoScrollViewPager. My requirement is like I want to display some screens and each screen has different data and different location on map.
All screens are swipable and swipes automatically too, so I used AutoScrollViewPager for this. In AutoScrollViewPager, I used AutoScrollViewPagerAdapter to add data on screens. Now I want different map on each screen which shows different locations for different screen.
I used SupportMapFragment, MapView for this but both does not allow me create different maps for each screen in adapter. Also Adapter does not have any method related to lifecycle of fragment or activity.
I don't think you would be needing fully functional maps in the ViewPaper. If you are just looking to show the location on the map, you can simply use images for that. Use the Google Static Maps API to get the images for the locations and show them in the ViewPager.
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...
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'm trying to "port" an iOS app to Android.
The original iOS app workflow is:
Tab 1
List1 -> Detail -> DetailMap
Tab 2
List2 -> Detail -> DetailMap
Tab 3
Map -> Detail
Where "List1" and "List2" are lists of places, "Detail" shows info about a place, "DetailMap" shows where the place is on the map. "Map" is a simple map with markers the user can click to reach "Detail".
What's the best way to implement this workflow in Android?
I know I should avoid using a TabActivity (deprecated), and instead use an action bar and fragments to provide navigation tabs.
Ok, but then how to implement navigation from "List1" to "Detail", and from "Detail" to "DetailMap"? I don't think it's possible to have fragments inside a fragment?
And what about the maps? I don't think it's possible to have a mapview inside a fragment, right?
I must be missing something (maybe a lot)...
One of the best components for this is the ViewPager.
http://tamsler.blogspot.com/2011/10/android-viewpager-and-fragments.html
and
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
You can see it in action in the new Android Market, or the Google+ App for Android.