Android – SupportMapFragment with GoogleMaps API 2.0 giving IllegalArgumentException

You can fix this, if you delete all nested fragments in onDestroyView(). Don’t know if it is a proper solution. public void onDestroyView() { super.onDestroyView(); Fragment fragment = (getFragmentManager().findFragmentById(R.id.map)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } And inflating them as usual in onCreateView() public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.map, container, … Read more

How to show multiple markers on MapFragment in Google Map API v2?

I do it like this to show car positions on the map with markers of different colors: private void addMarkersToMap() { mMap.clear(); for (int i = 0; i < Cars.size(); i++) { LatLng ll = new LatLng(Cars.get(i).getPos().getLat(), Cars.get(i).getPos().getLon()); BitmapDescriptor bitmapMarker; switch (Cars.get(i).getState()) { case 0: bitmapMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED); Log.i(TAG, “RED”); break; case 1: bitmapMarker = … Read more

Android map v2 zoom to show all the markers

You should use the CameraUpdate class to do (probably) all programmatic map movements. To do this, first calculate the bounds of all the markers like so: LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (Marker marker : markers) { builder.include(marker.getPosition()); } LatLngBounds bounds = builder.build(); Then obtain a movement description object by using the factory: CameraUpdateFactory: int … Read more