Skip to Main Content

Get Current Position

Use the Get Current Position dynamic action to fetch the device's current location.

It can return latitude and longitude, or a GeoJSON object, into page items or a custom JavaScript function can receive a Geolocation object as a parameter. The accuracy of the geolocation depends on the user's device.

For privacy reasons, each user is asked for permission upon the first use of this dynamic action. If the user denies permission, the Geolocation returned is null so your application should handle that possibility gracefully.

Compatibility

This table shows the supported combinations of operating systems and browsers for the Geolocation feature.

Chrome Edge Firefox Safari
Android Yes Yes Yes N/A
iOS Yes Yes Yes Yes
macOS Yes Yes Yes Yes
Windows Yes Yes Yes N/A

Last updated: April 2023

Edit Dynamic Action

Instructions

  1. In Page Designer add two items: P1_LATITUDE and P1_LONGITUDE
  2. Create a Button
  3. Add a Dynamic Action to the button click event
  4. Change the Action to Get Current Position
  5. Set the Return Type to Latitude and Longitude
  6. Set the Latitude Item to P1_LATITUDE to return latitude into it
  7. Set the Longitude Item to P1_LONGITUDE to return longitude into it

Data Type

The Get Current Position dynamic action can be used to return the data in three different ways. Choose between returning the GeoJSON to a page item, Latitude and Longitude to a page item, or full object to a JavaScript function.

GeoJSON

Returns a JSON with all the location content:

GeoJSON Code

{ "latitude":20.7195718, "longitude":-103.4363326, "altitude":null, "accuracy":16.452, "altitudeAccuracy":null, "heading":null, "speed":null }

Latitude and Longitude

Returns Latitude and Longitude in separated values:

Latitude and Longitude Code

P1_LATITUDE: 20.7195613 P1_LONGITUDE: -103.4363368

JavaScript Function

Returns full Geolocation object to a custom JavaScript function:

JavaScript Function Code

function( position, event ) { apex.debug.log( position, event ); }

Examples

iOS requesting permission

iOS returning geolocation

Demo

Tap the Geolocate button to find your current position. Your browser may ask your permission to provide this information to the page. This app doesn't save that information anywhere.