Returns the current location of the device.
$m.getLocation(function(response){ if(response.code){ var coords = response.result.position.coords; $m.alert("Your location-" + coords.latitude + "-" + coords.longitude); } else{ $m.alert(response.error.message); } ); |
Syntax
$m.getLocation(fp_callback)
$m.getLocation(options, fp_callback)
Parameters
options
object (optional)
Optional parameters for the getLocation operation. It can contain one or more of the following properties,
- enableHighAccuracy - {Boolean}. True, if the location needs to be accurate. Setting true would activate gps receiver and hence the battery consumption will be higher. Default value is false.
- timeout - {Number}. Timeout for receiving location information in seconds. If the location is not received within the specified time, the location tracking is cancelled and a timeout error is thrown.
fp_callback
function (required)
Function to execute after the location information is obtained. The function receives a response object as parameter, with the following properties,
- code - {Integer}. 0 if the location providers are not enabled or any other errors. 1, otherwise.
- result - {Object}. Object containing the following properties,
- coords - {Object}. Location information containing properties,
- latitude - {Number}.
- longitude - {Number}.
- altitude - {Number}.
- horizontalAccuracy - {Number}.
- verticalAccuracy - {Number}.
- speed - {Number}.
- heading - {Number}.
- timestamp - {Number}. Time when the location information is read.
- error - {Object}. The error object contains,
- message - {String}. A short description of the error.
- description - {String}. A detailed description of the error.