我正在使用适用于Android的Google Maps API V2,我想知道Google的新导航抽屉是否可以与MapFragement互动。 在抽屉中会有一个航点列表,当用户点击它时,地图将以点击的航点为中心。
对不起英语,谢谢你。
答案 0 :(得分:0)
当然有可能。对于我的一个项目,我不使用它,但这是方法。我使用了SherlockMapFragment(为了更好的兼容性),但它与MapFragment
一样class DrawerItemClickListener implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
case 0:
SherlockMapFragment someFragment= new FragmentSome();
Bundle args1 = new Bundle();
args1.putInt("index", DATA_SLEEP); // here put some data
someFragment.setArguments(args1);
fm.beginTransaction().replace(R.id.contentFrame, someFragment)
.commit();
getSupportActionBar().setTitle("I am fragment");
drawerLayout.closeDrawer(drawerList);
break;
然后在创建捕获的片段上,由地图片段实例化的新地图将其存储在视图中,将其添加到膨胀的布局并使用gmap = getMap()获取对它的引用然后使用gmap这是地图对象:
public class FragmentSome extends SherlockMapFragment{
private GoogleMap gMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
private View mapView;
mapView = super.onCreateView(inflater, container, savedInstanceState); //
sore map in a view
initType = getArguments().getInt("index");
loadData();
return inflater.inflate(R.layout.fragment_food_sleep, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FrameLayout mapHolder = (FrameLayout) getView().findViewById(
R.id.mapContainer);
mapHolder.addView(mapView); // add map to inflated layout
gMap = getMap(); // get reference to map and from here do whatever...
if (initType == MainActivity.DATA_FOOD) {
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
46.390752, 16.437006), 5));
gMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
} else {
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
46.388322, 16.427994), 5));
gMap.animateCamera(CameraUpdateFactory.zoomTo(13), 2000, null);
}
}