Device.getDeviceLocation()
Overview
Retrieves the current GPS coordinates of the device. The host profile must have Location services turned on and the user must have accepted the consent notification before the data can be retrieved. To check if consent has been granted, use Device.getLocationConsent().
Android and Windows only
Added in version 2.1.47
Format
var callback = function(location) { /*...*/ };
Device.getDeviceLocation(callback);
| Parameter | Description | Type | Required | Notes |
|---|---|---|---|---|
| callback | A function that should be called with the result from the GPS. | Function | Required | The location parameter passed to the callback can be null or undefined if the location is not available. |
Location object properties
| Value | Description | Type |
|---|---|---|
| accuracy | Returns the estimated horizontal accuracy radius in meters of this location at the 68th percentile confidence level. This means that there is a 68% chance that the true location of the device is within a distance of this uncertainty of the reported location. Another way of putting this is that if a circle with a radius equal to this accuracy is drawn around the reported location, there is a 68% chance that the true location falls within this circle. | Number |
| latitude | Latitude of this location. The value is between -90.0f (South) and 90.0f (North) inclusive. | Number |
| longitude | Longitude of this location. The value is between -180.0f (West) and 180.0f (East) inclusive. | Number |
Example
Copy
/* Get the location and show in a toast
*/
Device.getDeviceLocation(function(loc) {
if (loc) {
View.toast(`Latitiude: ${loc.latitude}. Longitude: ${loc.longitude}. Accuracy: ${loc.accuracy}`);
} else {
View.toast("Location not available");
}
})
mqttClient.connect();