GPS Property

Applies to TestComplete 15.0, last modified on November 17, 2021
The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.

Description

Returns the current location of the mobile device and allows specifying a mock location. See Geolocation Testing (Legacy).

You can access this property on Android only if the Android Agent service is installed and running on the device.

Declaration

AndroidDeviceObj.GPS

Read-Only Property An AndroidGPS object
AndroidDeviceObj An expression, variable or parameter that specifies a reference to an AndroidDevice object

Applies To

The property is applied to the following object:

Property Value

The AndroidGPS object that returns the current location of the mobile device and allows specifying a mock location.

Example

The code below retrieves location data from the Android device's GPS sensor, posts them to the test log and shows the location in Google Maps:

JavaScript, JScript

function PostGPSLocation()
{
  Mobile.SetCurrent("Nexus 7");
  // Enable GPS
  Mobile.Device().GPS.GPSEnabled = true;
  // Obtain location data
  var Longt = Mobile.Device().GPS.Location.Longitude;
  var Lat = Mobile.Device().GPS.Location.Latitude;
  // Output the location data
  Log.Message("The device location is:");
  Log.Message("Longitude: " + aqConvert.VarToStr(Longt));
  Log.Message("Latitude: " + aqConvert.VarToStr(Lat));
  Log.Message("Altitude: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Altitude));
  Log.Message("Accuracy: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Accuracy));
  // Open Google Maps in the browser and pass the coordinates as URL parameters
  Browsers.Item(Browsers.btIExplorer).Run("http://maps.google.com/maps?q=loc:" + aqConvert.VarToStr(Lat) + "," + aqConvert.VarToStr(Longt));
}

Python

def PostGPSLocation():
  Mobile.SetCurrent("Nexus 7")
  # Enable GPS
  Mobile.Device().GPS.GPSEnabled = True
  # Obtain location data
  Longt = Mobile.Device().GPS.Location.Longitude
  Lat = Mobile.Device().GPS.Location.Latitude
  # Output the location data
  Log.Message("The device location is:")
  Log.Message("Longitude: " + IntToStr(Longt))
  Log.Message("Latitude: " + IntToStr(Lat))
  Log.Message("Altitude: " + VarToStr(Mobile.Device().GPS.Location.Altitude))
  Log.Message("Accuracy: "+ VarToStr(Mobile.Device().GPS.Location.Accuracy))
  # Open Google Maps in the browser and pass the coordinates as URL parameters
  Browsers.Item[Browsers.btIExplorer].Run("http://maps.google.com/maps?q=loc:" + IntToStr(Lat) + "," + IntToStr(Longt))

VBScript

Sub PostGPSLocation
  Call Mobile.SetCurrent("Nexus 7")
  ' Enable GPS
  Mobile.Device.GPS.GPSEnabled = true
  ' Obtain location data
  Longt = Mobile.Device.GPS.Location.Longitude
  Lat = Mobile.Device.GPS.Location.Latitude
  ' Output the location data
  Call Log.Message("The device location is:")
  Call Log.Message("Longitude: "& aqConvert.VarToStr(Longt))
  Call Log.Message("Latitude: "& aqConvert.VarToStr(Lat))
  Call Log.Message("Altitude: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.Altitude))
  Call Log.Message("Accuracy: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.Accuracy))
  ' Open Google Maps in the browser and pass the coordinates as URL parameters
  Call Browsers.Item(Browsers.btIExplorer).Run("http://maps.google.com/maps?q=loc:" & aqConvert.VarToStr(Lat) & "," & aqConvert.VarToStr(Longt))
End Sub

DelphiScript

procedure PostGPSLocation;
var Longt, Lat;
begin
  Mobile.SetCurrent('Nexus 7');
  // Enable GPS
  Mobile.Device.GPS.GPSEnabled := true;
  // Obtain location data
  Longt := Mobile.Device.GPS.Location.Longitude;
  Lat := Mobile.Device.GPS.Location.Latitude;
  // Output the location data
  Log.Message('The device location is:');
  Log.Message('Longitude: ' + aqConvert.VarToStr(Longt));
  Log.Message('Latitude: ' + aqConvert.VarToStr(Lat));
  Log.Message('Altitude: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.Altitude));
  Log.Message('Accuracy: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.Accuracy));
  // Open Google Maps in the browser and pass the coordinates as URL parameters
  Browsers.Item(Browsers.btIExplorer).Run('http://maps.google.com/maps?q=loc:'+aqConvert.VarToStr(Lat) + ',' + aqConvert.VarToStr(Longt));
end;

C++Script, C#Script

function PostGPSLocation()
{
  Mobile["SetCurrent"]("Nexus 7");
  // Enable GPS
  Mobile["Device"]["GPS"]["GPSEnabled"] = true;
  // Obtain location data
  var Longt = Mobile["Device"]["GPS"]["Location"]["Longitude"];
  var Lat = Mobile["Device"]["GPS"]["Location"]["Latitude"];
  // Output the location data
  Log["Message"]("The device location is:");
  Log["Message"]("Longitude: " + aqConvert["VarToStr"](Longt));
  Log["Message"]("Latitude: " + aqConvert["VarToStr"](Lat));
  Log["Message"]("Altitude: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["Altitude"]));
  Log["Message"]("Accuracy: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["Accuracy"]));
  // Open Google Maps in the browser and pass the coordinates as URL parameters
  Browsers["Item"](Browsers["btIExplorer"])["Run"]("http://maps.google.com/maps?q=loc:" + aqConvert["VarToStr"](Lat) + "," + aqConvert["VarToStr"](Longt));
}

See Also

Testing Mobile Applications
Geolocation Testing (Legacy)
AndroidGPS Object
AndroidDevice Object

Highlight search results