Mapview In Fragment ( Android 4.0 Or Higher)
I've been looking for a while to find a good tutorial with code example for a MapView in Fragment for ICS. Anyone have any links?
Solution 1:
Here is a book's sample application showing how to have a MapView
in a Fragment
in an API Level 11+ app. It's mostly just a MapActivity
. Here are the key bits of the fragment that loads the MapView
:
publicclassMapFragmentextendsFragment {
privateMapView map=null;
privateMyLocationOverlay me=null;
@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return(newFrameLayout(getActivity()));
}
@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
map=newMapView(getActivity(), "0mjl6OufrY-tHs6WFurtL7rsYyEMpdEqBCbyjXg");
map.setClickable(true);
map.getController().setCenter(getPoint(40.76793169992044,
-73.98180484771729));
map.getController().setZoom(17);
map.setBuiltInZoomControls(true);
Drawable marker=getResources().getDrawable(R.drawable.marker);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());
map.getOverlays().add(newSitesOverlay(marker));
me=newMyLocationOverlay(getActivity(), map);
map.getOverlays().add(me);
((ViewGroup)getView()).addView(map);
}
// rest of fragment here
}
Solution 2:
I have answered to the same question here MapView in a Fragment (Honeycomb)
Post a Comment for "Mapview In Fragment ( Android 4.0 Or Higher)"