Skip to content

App as location source

Jiří M. aka Menion edited this page Feb 8, 2019 · 1 revision

On many places in Locus Map is used grid with various location sources for point, search etc.

Your own application as another source? Definitely possible.

Workflow

1. Register intent-filter in your activity

<intent-filter>
    <action android:name="locus.api.android.INTENT_ITEM_GET_LOCATION" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

2. Handle received click in your activity as follows:

public override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...

    // check intent that started activity
    if (IntentHelper.isIntentGetLocation(intent)) {

        // create and return a new location with the defined name
        IntentHelper.sendGetLocationData(act,
                "Non sence Loc ;)",
                Location().apply {
                    latitude = Math.random() * 85
                    longitude = Math.random() * 180
                })
    }
}

3. Received "Get location" request (intent) also may contain users GPS (if enabled) and map center location. It may be obtained by:

// GPS location
val locGps: Location? = IntentHelper.getLocationFromIntent(intent, LocusConst.INTENT_EXTRA_LOCATION_GPS)
// location of map center
val locMapCenter: Location? = IntentHelper.getLocationFromIntent(intent, LocusConst.INTENT_EXTRA_LOCATION_MAP_CENTER)