I have a question . I'm trying to use MapView in Google Maps Android API v2 . I'm read in document . They said that
MapView, a subclass of the Android View class, allows you to place a map in an Android View. A View represents a rectangular region of the screen, and is a fundamental building block for Android applications and widgets. Much like a MapFragment, the MapView acts as a container for the Map, exposing core map functionality through the GoogleMap object.
It may be MapView and MapFragment are the same thing . In Google Maps Android API v1 , MapView extend MapActivity . But in Google Maps Android API v2 , I can use it any more . I see the tutorial
How do you display Google Maps via new Google Maps API v2 on Android?
They advice to extend FragmentActivity . But in my layout xml , I just use
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
It doesn't have prefix fragment like MapFragment . And when it displays , It looks like when I use MapFragment . May be both of them is the same thing ???? I'm not clear about that . Anyone can explain for me . Sorry my English is not good !!!
Related
I am new to Android Development and I would like to know what is the easiest way that i can insert google maps in fragments. All guides I have found online are rather difficult for a beginner-level developer.
All help is appreciated.
this guide is pretty simple and easy to work with. Try it out.
https://github.com/codepath/android_guides/wiki/Google-Maps-Fragment-Guide
Google Maps is integrated in your app using the SupportMapFragment class. So you see, map itself is type of fragment. Now the question really is, how to insert fragments into your activity.
You can do it via XML or progrmatically. For XML insertion, you can insert this code into your XML :
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Then in your java file, you would get a refrence of this fragment like this :
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMapFragment);
In case you have your own custom fragment and would like to insert a map fragment into your custom fragment, you will follow the same strategy above but will have the XML and Java code in your respective custom fragment files.
I have an app having actionbar where one of the fragments contain a mapFragment. Also, i've to make an overlay of list on top of the map. MapFragment as of now as lesser functionality(i cant make setInfoWindowAdapter to work in it).So my question is should I be using Mapview within a fragment or MapFragment within in a fragment? which is the best practice?
I've read through many articles but none them exactly mention which is the best option and why.
Both are correct if done correct.
Fragments inside fragments are supported as of support library v11.
Two things to remember:
you cannot put MapFragment to xml
you have to use getChildFragmentManager
Check this link for how to correctly add MapFragment inside your fragment: http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1
I want to display Map in one of my Fragment I am using 4 fragments in which one shows the map but i don't want to use LocalActivityManagerto host a Activity inside a fragment. It is a deprecated class, but it offers the simplest solution.
By using MapActivity it is starting a new Activity which i don't want i want to display it in viewpager and MapView dont work in Fragment.
Please suggest me how to get it.
Thanks for Help.
Since Maps V1 (MapActivity and kin) is deprecated, you could consider moving to the new Maps V2, which has MapFragment (for native API Level 11 fragments) and SupportMapFragment (for the Android Support Library's backport of fragments).
I found no other way then the one mentioned in the following way...
https://stackoverflow.com/a/8126287
Can somebody give me a good example on how to use a MapView with the ActionBar in Android 4.0 ICS?
Isn't there something like a MapFragment or so?
I want my app to have view control in the actionbar (dropdownlist for navigation) and one of the fragments has to be a map
Google Maps API for Android v2 has MapFragment. It's documented in developers.google.com.
I have a working mapview application in which I can hit a service and show GPoints on the map as overlay.
What I want to do next is show an encoded Gpolyline as an overlay on my mapView.
When I try to instantiate a GPolyline polyline object in my main activity, eclipse doesn't recognize the class. Is there a library import I am missing?
A quick example of adding a GPolyline to the mapView in an android application would be a great help.
I think the problem you're having is that there aren't GPolyline's in Android's version of Google Maps, they're Javascript/AJAX specific. What you want to do is draw out the lines manually in an Overlay or OverlayItem. See this answer, for more details on specifically how to do this.
The Hello, MapView tutorial has a short example on drawing to an Overlay and the com.google.android.maps package docs should show you what's available in Android's version of Google Maps.