我一直在寻找一段很好的教程,在片段中为ICS找到MapView的代码示例。
任何人都有链接?
答案 0 :(得分:8)
Here is a book's sample application显示了如何在API Level 11+应用中的MapView
中拥有Fragment
。它主要只是一个MapActivity
。以下是加载MapView
的片段的关键位:
public class MapFragment extends Fragment {
private MapView map=null;
private MyLocationOverlay me=null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return(new FrameLayout(getActivity()));
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
map=new MapView(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(new SitesOverlay(marker));
me=new MyLocationOverlay(getActivity(), map);
map.getOverlays().add(me);
((ViewGroup)getView()).addView(map);
}
// rest of fragment here
}
答案 1 :(得分:0)
我在这里回答了同样的问题MapView in a Fragment (Honeycomb)