Skip to content

Advanced point handling

Jiří M. aka Menion edited this page Feb 7, 2019 · 2 revisions

Except creating and displaying of points, Locus API offer some few very interesting options.

OnClick callback

Imagine your add-on display point on a map. Since that moment, you lost contact with your point. What if you want to react on user events and do something more with point, once clicked? For this, exists OnClick callback feature.

Prepare ID that will identify event once received

public static final String EXTRA_ON_DISPLAY_ACTION_ID = "myOnDisplayExtraActionId";

Define callback on prepared point

point.setExtraOnDisplay(
    "com.asamm.locus.api.sample",
    "com.asamm.locus.api.sample.MainActivity",
    EXTRA_ON_DISPLAY_ACTION_ID,
    "id01");

First two parameters define package name and class name of activity, that receive event. Third parameter is our ACTION_ID and last is unique identification of point.

Handle received intent

Once your activity starts, check content of intent

if (getIntent().hasExtra(EXTRA_ON_DISPLAY_ACTION_ID)) {
    // get ID of point
    String id = getIntent().getStringExtra(EXTRA_ON_DISPLAY_ACTION_ID);

    // now we should have ID of point. We may for example generate new improved version ...
    Waypoint pt = ... create new point
    pt.addParameter(ExtraData.PAR_DESCRIPTION,
        "Extra description to ultra improved point!, received value:" + value);
    // ... and send it back
    Intent retInent = LocusUtils.prepareResultExtraOnDisplayIntent(pt, true);
    act.setResult(Activity.RESULT_OK, retInent);
    act.finish();

    // or we should just display dialog/toast to user
    new AlertDialog.Builder(act).
        setTitle("Intent - PickLocation").
        setMessage("Some message ...").
        setPositiveButton("Close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {}
        }).show();
}

Find point by 'name'

Locus API offer to search in Locus database and get points defined by name.

ActionTools.getLocusWaypointId(context, locusVersion, name);

Name parameter use wildcards, so following options are valid

  • search for point that has exact name "Cinema", just write "Cinema" as name
  • search for point that starts with "Cinema", just write "Cinema%" as name
  • search for point that contains word "cinema", just write "%cinema%" as name

Result of search is list of found points, better it's ID's.

Load point by it's ID

With known ID of point, we may load full point over Locus API

Waypoint point = ActionTools.getLocusWaypoint(context, locusVersion, pointId);

Display point screen

With known ID of point, we may also display big point screen directly in Locus.

ActionTools.displayWaypointScreen(context, locusVersion, pointId);

This method exists in advanced variation, where callback may be also defined and Locus then report back even when point screen is closed.

Clone this wiki locally