1. Enable HyperTrackMapFragment by adding the following fragment snippet in your Activity’s layout file
// Add the fragment below in your activity's layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
<fragment
android:id="@+id/htMapfragment"
android:name="com.hypertrack.lib.HyperTrackMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_map" />
...
</LinearLayout>
2. Enable customizations of UI elements by creating a class extending HyperTrackMapAdapter
//Extend HyperTrackMapAdapter for customizing UI elements in the map view
public class MyMapAdapter extends HyperTrackMapAdapter {
...
@Override
public boolean showPlaceSelectorView() {
return true;
}
@Override
public boolean enableLiveLocationSharingView() {
return true;
}
@Override
public CameraUpdate getMapFragmentInitialState(HyperTrackMapFragment
hyperTrackMapFragment) {
if (SharedPreferenceManager.getLastKnownLocation() != null) {
LatLng latLng = new LatLng(defaultLatitude, defaultLongitude);
return CameraUpdateFactory.newLatLngZoom(latLng, 15.0f);
}
return super.getMapFragmentInitialState(hyperTrackMapFragment);
}
...
}
3. To get callback on various events which happen on HyperTrackMapFragment, construct an instance of the class MapFragmentCallback
private MapFragmentCallback mapFragmentCallback = new MapFragmentCallback() {
...
@Override
public void onExpectedPlaceSelected(Place expectedPlace) {
super.onExpectedPlaceSelected(expectedPlace);
if (expectedPlace != null) {
// Use this place to createAndAssignAction for current userId
}
}
...
};
4. Instantiate HyperTrackMapFragment in the onCreate method of the activity in which map fragment has been included
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
// Initialize HyperTrackMapFragment in Activity’s layout file to getMapAsync
HyperTrackMapFragment htMapFragment = (HyperTrackMapFragment) getSupportFragmentManager().findFragmentById(R.id.htMapfragment);
htMapFragment.setHTMapAdapter(new MyMapAdapter(MapActivity.this));
htMapFragment.setMapFragmentCallback(mapFragmentCallback);
...
}