Notice for App Developers

To use these methods some configurations in the native app are needed

  • IOS:

    • Add to info.plist the config with a description:
      • Privacy - Location Always and When In Use Usage Description
      • Privacy - Location Always Usage Description
      • Privacy - Location When In Use Usage Description
    • If you want to enable only approximate location precision, add:
      • Privacy - Location Default Accuracy Reduced - true
  • Android:

    • Add to AndroidManifest.xml
<manifest [...]>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
[...]
</manifest>

Hierarchy

  • Geolocation

Methods

  • Check permissions status for geolocation resource

    Example:

    const geolocationStatus = await Eitri.geolocation.checkPermission({precision: "precise"})
    console.log(geolocationStatus)

    /* Example output from this console.log:
    {
    status: "DENIED",
    details: {
    precision: "precise"
    }
    }
    */

    🚨 Android only: If executed before the first permission request, the default response is BLOCKED.

    Compatibility Control

    • API LEVEL 16 - Functionality added

    Parameters

    Returns Promise<GeolocationPermissionOutput>

  • Get the current location of the device

    Example:

    try {
    const geolocationStatus = await Eitri.geolocation.requestPermission({precision: "precise"})

    if (geolocationStatus.status == "GRANTED") {
    const location = await Eitri.geolocation.getCurrentLocation()
    console.log(location)
    /* Example output from this console.log:
    {
    "latitude": -22.9576466,
    "longitude": -43.1760832
    }
    */
    return
    }

    // handle other permission states
    // inform user

    } catch (e) {
    console.log(e)
    // handle errors and notify user
    }

    Returns Promise<GeolocationRequestOutput>

Generated using TypeDoc