Links
📍

Geolocation

If you're planning to use browser Geolocation API, make sure you've enabled the Geolocation feature for iOS (For Android, this feature is enabled by default)

🧋 Bubble.io Plugin

[Element] Natively - Location

Natively - Location element contains Foreground & Background location services:

📍 Foreground Location Tracking

Events:

  • Location received - User's location longitude & latitude values updated.
  • Location failed - called whenever Location service was not able to get user's location (check Latest location request status for more details)
  • Location Permission Received - called whenever Get location permission return a result

States:

  • Latest location longitude - Longitude as number
  • Latest location latitude - Latitude as number
  • Latest location response status - Status of the latest geolocation request call.
    • SUCCESS - Got a location and desired accuracy level was achieved successfully.
    • TIMEOUT - Got a location, but the desired accuracy level was not reached before timeout.
    • FAILED - An error occurred while using the system location services.
  • Location permission
    • IN_USE - foreground allowed
    • ALWAYS - background allowed
    • DENIED - not determined or denied

Actions:

  • Get current location
    • minAccuracy [iOS] - Radius in meters. All other values will be filtered!
    • accuractType [iOS] - Affects on location accuracy and battery life. BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers. More details here
    • Priority [Android] - "BALANCED" (To save battery, recommended) & "HIGH"
  • Start foreground location service - start fetching device location
    • minAccuracy [iOS] - Radius in meters. All other values will be filtered!
    • accuractType [iOS] - Affects on location accuracy and battery life. BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers. More details here
    • Priority [Android] - "BALANCED" (To save battery, recommended) & "HIGH"
    • Fetching Interval - Determines how often the location will be fetched. Interval in milliseconds. 5000ms -> 5s
  • Stop foreground location service - stop fetching device location
  • Get location permission - request location permission status update
On page reload, the location live tracking service will be automatically stopped. You need to run the Start live location service action.

🚙 Background location tracking (BETA) - v2.1.0

Before using background geolocation, make sure you've enabled it in your Natively App Dashboard + Created a new build.

States:

  • Latest location response status - Status of the latest background location service start/stop.
    • SUCCESS - Background location started/stopped successfully
    • FAILED - Background location started/stopped with an error.

Events:

  • Location background failed - Whenever starting of background service will fail
  • Location background success - Whenever starting of background service will succeed

Actions:

  • Start background location service - start fetching device location
    • minAccuracy [iOS] - Radius in meters. All other values will be filtered!
    • accuractType [iOS] - Affects on location accuracy and battery life. BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers. More details here
    • Priority [Android] - "BALANCED" (To save battery, recommended) & "HIGH"
    • Fetching Interval - Determines how often the location will be fetched. Interval in milliseconds. 5000ms -> 5s
    • Response Identifier - Identifier that will be sent with a user's location (We're recommending using the user's unique id)
  • Stop background location service - stop fetching device location
Background geolocation can be automatically stopped in such cases: If the user or system closes the app, or if the device receives more than 3 errors in response from your endpoint.
Unlike foreground location service, the background will not stop on page reload

Coordinates -> Marker address

To convert longitude and latitude to the bubble's geolocation, you need to use this formula:

🛠 JavaScript SDK

NativelyLocation

1
const locationService = new NativelyLocation()
2
const location_callback = function (resp) {
3
console.log(resp.status); // "Success"/"Timeout"/"Error"
4
console.log(resp.longitude); // 50.1231231
5
console.log(resp.latitude); // 50.1231231
6
};
7
const minAccuracy = 50 // only available in 2.7.0 minAccuracy [iOS] - Radius in meters. All other values will be filtered!
8
9
const accuracyType = "Best" // only available in 2.7.0 accuractType [iOS] - Affects on location accuracy and battery life. BestForNavigation,Best,NearestTenMeters,HundredMeters,Kilometer,ThreeKilometers. More details here https://developer.apple.com/documentation/corelocation/cllocationaccuracy
10
11
const priority_android = "BALANCED" // "BALANCED" or "HIGH" [Android only]
12
const inerval = 10000 // in milliseconds
13
// Foreground Location
14
locationService.current(minAccuracy, accuracyType, priority_android, location_callback);
15
locationService.start(interval, minAccuracy, accuracyType, priority_android, location_callback);
16
locationService.stop();
17
18
const location_bg_callback = function (resp) {
19
console.log(resp.status); // "SUCCESS"/"FAILED" - Start of background service was successfully or failed
20
};
21
// Background Location
22
const responseId = "my-user-id" // Identifer that you will receive together with coordinates to your webhook endpoint
23
locationService.startBackground(interval, minAccuracy, accuracyType, priority_android, responseId, location_bg_callback);
24
locationService.stopBackground(location_bg_callback);