I have a mapview for which I am calling mapview.getMapAsync and in onMapReady I am setting mMap = map. Then i am setting various properties like adding marker, zooming the map, animating camera to current location, setting map type, and selecting location of the current target of camera but nothing seems to work. Some snippet of my code is:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater,container,savedInstanceState);
view = inflater.inflate(R.layout.mymapview, container, false);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView = (MapView) view.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
if (mMap == null)
mapView.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
setUpMap();
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
markerLoader(true);
markerLoader(false);
}
private void setUpMap() {
mUiSettings = mMap.getUiSettings();
mMap.setMyLocationEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mUiSettings.setZoomControlsEnabled(true);
mUiSettings.setScrollGesturesEnabled(true);
mUiSettings.setMyLocationButtonEnabled(false);
mUiSettings.setRotateGesturesEnabled(false);
}
mymapview.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/locationMarker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_marginBottom="30dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/markerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Black"
android:textColor="@color/White"
android:text="Position & Click to\n select location"/>
<ImageView
android:id="@+id/marker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/marker_offline" />
</LinearLayout>
<RelativeLayout
android:id="@+id/top_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
<LinearLayout
android:id="@+id/button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
<ImageView
android:id="@+id/map_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:src="@drawable/map_layers" />
<ImageView
android:id="@+id/zoom_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/map_zoom_minus" />
<ImageView
android:id="@+id/loc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/map_layer"
android:layout_marginTop="16dp"
android:src="@drawable/location" />
<ImageView
android:id="@+id/zoom_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/zoom_out"
android:layout_alignParentRight="true"
android:layout_marginBottom="14dp"
android:src="@drawable/map_zoom_plus" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gpsButton"
android:layout_marginTop="60dp"
android:layout_marginLeft="12dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/gps"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/manualButton"
android:layout_marginTop="10dp"
android:layout_marginLeft="12dp"
android:layout_alignParentLeft="true"``
android:layout_below="@+id/gpsButton"
android:src="@drawable/manual"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/priveousButton"
android:layout_marginTop="10dp"
android:layout_marginLeft="12dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/manualButton"
android:src="@drawable/previous"/>
</RelativeLayout>
I am not able to find where i am going wrong.