Place Selector Widget

PlaceSelector

Place Selector widget enables the user to create a Place object with one of either user's recently selected places, his current location, place suggestions, and pinnable locations. This guide will cover how to enable Place Selector View.

Where would it be useful?

You can use the Place Selector widget to enable user to pick a place of his/her choice. One use-case is to build a live location sharing messaging app using HyperTrack APIs.

Advantages:

  1. Reduces development time
  2. Free
  3. Includes the pinnable locations on a map
  4. Provides reverse-geocoded place suggestions

Enabling Place Selector widget

Add HyperTrackMapFragment in activity's layout file

Place Selector View is embeded in HyperTrackMapFragment. You need to add HyperTrackMapFragment snippet in your activity 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_new" />
    ...
</LinearLayout>

Get selected places

Enable view by creating a class extending HyperTrackMapAdapter. This view is DISABLED by default.

//Extend HyperTrackMapAdapter for customizing UI elements in the map view
public class MyMapAdapter extends HyperTrackMapAdapter {
    ...
    @Override
    public boolean showPlaceSelectorView() {
        return true;
    }
    ...
}

To get a selected Place object, create an object of class MapFragmentCallback from SDK and overide a method onExpectedPlaceSelected(Place expectedPlace).

private MapFragmentCallback mapFragmentCallback = new MapFragmentCallback() {
    ...
    @Override
    public void onExpectedPlaceSelected(Place expectedPlace) {
        super.onExpectedPlaceSelected(expectedPlace);
        if (expectedPlace != null) {
            // Use this place
    }
    }
    ...
};

Intialize HyperTrackMapFragment and start Activity

Inside onCreate method of your aactivity containing the map view and set HTMapFragmentCallback to receive user's selected place object.

// Initialize Map Fragment added in MyMapActivity Layout
HyperTrackMapFragment htMapFragment = (HyperTrackMapFragment) getSupportFragmentManager().findFragmentById(R.id.htMapfragment);
adapter = new MyMapAdapter(this, getToolbar());
htMapFragment.setHTMapAdapter(adapter);
htMapFragment.setMapFragmentCallback(callback);

Start your activity containing HyperTrackMapFragment snippet and you can receive user's selected place object in MapFragmentCallback method onExpectedPlaceSelected(Place expectedPlace)

Intent intent = new Intent(this, MyMapActivity.class);
startActivity(intent);

results matching ""

    No results matching ""