Salesforce

How Do I Get the Device Location Using the GPS Capabilities of the Mobile Device? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Get the Device Location Using the GPS Capabilities of the Mobile Device? (Magic xpa 3.x)

You can find the device’s location and use GPS capabilities with your mobile applications using the ClientOSEnvGet function. You can use both the internal or connected GPS service.

  1. Create an Update Variable operation.

  2. In the With property, enter the following expression: ClientOSEnvGet ('device_location'). This will return the current device location, using any of the available location options (GPS, Network, and so on).


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 and Windows 10 Mobile 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 and Windows 10 Mobile 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:

  • 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. You should make sure to build in an indication to the user, such as “Searching for GPS location...”.

  • 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)

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.

Platform specific: For Windows 10 Mobile devices, you need to define that your application uses the GPS capabilities. This is done by adding the line <DeviceCapability Name="location"/> to the Package.AppxManifest file located in the RIAModules\Windows10Mobile\Source\MagicApp folder.

See also

How Do I Access Third-Party Applications from My Mobile Application?

Reference
Attachment 
Attachment