Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a frame for map in which it will be added in your xml layout</p> <pre><code>&lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map_container"&gt; &lt;!-- The map fragments will go here --&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Don't include class="com.google.android.gms.maps.SupportMapFragment" in xml either in your fragment class do get it manually inside onActivityCreated</p> <pre><code> @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); FragmentManager fm = getChildFragmentManager(); fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); if (fragment == null) { fragment = SupportMapFragment.newInstance(); fm.beginTransaction().replace(R.id.map_container, fragment).commit(); } /***at this time google play services are not initialize so get map and add what ever you want to it in onResume() or onStart() **/ } @Override public void onResume() { super.onResume(); if (map == null) { map = fragment.getMap(); map.addMarker(new MarkerOptions().position(new LatLng(0, 0))); } } </code></pre> <p>if you guys face any problem Illegal State Exception Occur just write below code</p> <p>/* * This issue Is tracked in (Google Bugs) * <a href="http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064">http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064</a> Added * Code Due to Illegal State Exception Occur when reclicking on tab * * A short-term workaround that fixed it for me is to add the following to * onDetach() of every Fragment which you call */</p> <pre><code>@Override public void onDetach() { super.onDetach(); try { Field childFragmentManager = Fragment.class .getDeclaredField("mChildFragmentManager"); childFragmentManager.setAccessible(true); childFragmentManager.set(this, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } </code></pre> <p>//If you want to show map in activity just extend your Activity by //FragmentActivity write code mention below</p> <p>In onCreate</p> <pre><code>FragmentManager fm = getSupportFragmentManager(); fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); if (fragment == null) { fragment = SupportMapFragment.newInstance(); fm.beginTransaction().replace(R.id.map_container, fragment) .commit(); } </code></pre> <p>In onResume</p> <pre><code>@Override protected void onResume() { super.onResume(); if (googleMap == null) { initilizeMap(); } } private void initilizeMap() { if (googleMap != null) { googleMap = fragment.getMap(); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.getUiSettings().setMyLocationButtonEnabled(true); googleMap.getUiSettings().setCompassEnabled(true); googleMap.getUiSettings().setRotateGesturesEnabled(true); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(latitude, longitude)).zoom(10).build(); googleMap.animateCamera(CameraUpdateFactory .newCameraPosition(cameraPosition)); // create marker MarkerOptions marker = new MarkerOptions().position(new LatLng( latitude, longitude)); // ROSE color icon marker.icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_ROSE)); // adding marker googleMap.addMarker(marker); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } } </code></pre> <p>Additional help can get from these links<br> <a href="https://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1">https://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1</a> <a href="https://developers.google.com/maps/documentation/android/map">https://developers.google.com/maps/documentation/android/map</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload