Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Created September 23, 2017 21:00
Show Gist options
  • Save ponnamkarthik/f06f4ee605796cdd4fe01a292fe71be3 to your computer and use it in GitHub Desktop.
Save ponnamkarthik/f06f4ee605796cdd4fe01a292fe71be3 to your computer and use it in GitHub Desktop.
How to add MapFragment inside a Fragment Android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorPrimary">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapFragment mapFragment = (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
googleMap = map;
if(location_live != null) {
LatLng latLng = new LatLng(location_live.getLatitude(), location_live.getLongitude());
googleMap.addMarker(new MarkerOptions().position(latLng)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment