Salesforce

Finding the Device Location (GPS) (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

Finding the Device Location (GPS) (Magic xpa 4.x)

The ClientOSEnvGet function can also be used to query the current device location using the internal or connected GPS device. The function syntax is as follows:

ClientOSEnvGet ('device_location') – returns the current device location, using any of the available location options (GPS, Network, etc.). The result is a string in the following format: OK|Latitude|Longitude, where OK is a fixed part for testing if a result was returned, and Latitude and Longitude are the coordinates of the current location. If a location could not be obtained, for any reason, an error message will be returned.

On Android devices, the GPS timeout is 20 seconds: 10 seconds to get the location from the GPS and if that fails, 10 seconds to get the location from the network.

On iOS devices, the GPS timeout is 10 seconds. These devices will use the GPS or network according to their internal rules.

You can also set the timeout for getting the location from both the GPS and network. You do this by using the following syntax: ClientOSEnvGet ('device_location|xxx|yyy ') where xxx is the number of seconds to wait for the GPS location and yyy is the number of seconds to wait for the network location. (Since version: 3.2a)

On iOS devices, only the GPS timeout value is used. These devices will use the GPS or network according to their internal rules.

For example: ClientOSEnvGet ('device_location|5|0') will only wait for 5 seconds for an answer from the GPS and will not wait to ask for a network location.

Note:

  • From Android 6 and above, if your app needs to access the GPS, a screen will appear asking for permission to access the device's location. (Since version: 3.2a)

  • Location queries can sometimes take time to respond, because the GPS device is searching for satellites. During this time, the client is blocked, waiting for a response. Developers should make proper indications for the user that this is the situation.

  • This operation opens the connection to the GPS and closes it once the data is received. If you need to frequently get the GPS data, you should consider keeping the GPS connection open by writing native code to do so.

After you have the GPS location, you can show a map with this location using a 3rd party application, for example by using the Invoke OS Cmd operation with Execute On=Client with any of the following expressions:

  • You can directly enter: https://maps.google.com/?q='&Trim (GPS Location). If the Google Maps application is installed on the device, you will be asked to decide in which application to display the location.

  • You can use 'geo:'&Trim (GPS Location). This will display each application that can display a geographical address.

  • You can load a specific application directly by using its name, such as: 'waze://?q=London' to open the Waze GPS application and navigate to London.

Reference
Attachment 
Attachment