来自Josh Holtz在GitHub上的示例:
您应该添加
MapView在你
Layout喜欢
<com.google.android.gms.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
并实现你的
Fragment喜欢
public class SomeFragment extends Fragment {MapView mapView;GoogleMap map;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.some_layout, container, false); // Gets the MapView from the XML layout and creates it mapView = (MapView) v.findViewById(R.id.mapview); mapView.onCreate(savedInstanceState); // Gets to GoogleMap from the MapView and does initialization stuff map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true); // Needs to call MapsInitializer before doing any CameraUpdateFactory calls try { MapsInitializer.initialize(this.getActivity()); } catch (GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } // Updates the location and zoom of the MapView CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10); map.animateCamera(cameraUpdate); return v;}@Overridepublic void onResume() { mapView.onResume(); super.onResume();}@Overridepublic void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); mapView.onLowMemory(); }}


