iOSGPS Object

Applies to TestComplete 15.69, last modified on November 13, 2024
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

The iOSGPS object provides an interface to the GPS sensor of the connected mobile device. You can use this object to get the current location of the device or to specify a mock location. See Geolocation Testing (Legacy).

The GPS object is returned by the Device.GPS property.

In order for TestComplete to access the GPS data:
  • The prepared application must be running on the device

  • Location Services must be enabled on the device, and your running application must have a permission to use your location. To give the application the needed permission, trigger the Location Services prompt for the application. You can do this from TestComplete by viewing the Mobile.Device("MyDevice").GPS.Location property in the Object Browser, or by running the following code from a test:

    JavaScript, JScript

    Mobile.Device("MyDevice").GPS.Location;

    Python

    Mobile.Device('MyDevice').GPS.Location

    VBScript

    Mobile.Device("MyDevice").GPS.Location

    DelphiScript

    Mobile.Device('MyDevice').GPS.Location;

    C++Script, C#Script

    Mobile["Device"]("MyDevice")["GPS"]["Location"];

Members

Example

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

JavaScript, JScript

function PostGPSLocation()
{
  Mobile.SetCurrent("iPad");
  // Check whether GPS is enabled
  if (Mobile.Device().GPS.GPSEnabled)
  {
    // 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("VerticalAccuracy: "+ aqConvert.VarToStr(Mobile.Device().GPS.Location.VerticalAccuracy));
    Log.Message("HorizontalAccuracy: "+ aqConvert.VarToStr(Mobile.Device().GPS.Location.orizontalAccuracy));
    Log.Message("Course: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Course));
    Log.Message("Speed: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Speed));
    // 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("iPad")
  # Check whether GPS is enabled
  if Mobile.Device().GPS.GPSEnabled:
    # 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("VerticalAccuracy: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.VerticalAccuracy))
    Log.Message("HorizontalAccuracy: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.HorizontalAccuracy))
    Log.Message("Course: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Course))
    Log.Message("Speed: " + aqConvert.VarToStr(Mobile.Device().GPS.Location.Speed))
    # 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))

VBScript

Sub PostGPSLocation
  Call Mobile.SetCurrent("iPad")
  ' Check whether GPS is enabled
  If Mobile.Device.GPS.GPSEnabled Then
    ' 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("VerticalAccuracy: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.VerticalAccuracy))
    Call Log.Message("HorizontalAccuracy: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.HorizontalAccuracy))
    Call Log.Message("Course: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.Course))
    Call Log.Message("Speed: "& aqConvert.VarToStr(Mobile.Device.GPS.Location.Speed))
    ' 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 If
End Sub

DelphiScript

procedure PostGPSLocation;
var Longt, Lat;
begin
  Mobile.SetCurrent('iPad');
  // Check whether GPS is enabled
  if Mobile.Device.GPS.GPSEnabled then
  begin
    // 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('VerticalAccuracy: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.VerticalAccuracy));
    Log.Message('HorizontalAccuracy: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.HorizontalAccuracy));
    Log.Message('Course: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.Course));
    Log.Message('Speed: ' + aqConvert.VarToStr(Mobile.Device.GPS.Location.Speed));
    // 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;
end;

C++Script, C#Script

function PostGPSLocation()
{
  Mobile["SetCurrent"]("iPad");
  // Check whether GPS is enabled
  if (Mobile["Device"]["GPS"]["GPSEnabled"])
  {
    // 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"]("VerticalAccuracy: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["VerticalAccuracy"]));
    Log["Message"]("HorizontalAccuracy: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["HorizontalAccuracy"]));
    Log["Message"]("Course: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["Course"]));
    Log["Message"]("Speed: " + aqConvert["VarToStr"](Mobile["Device"]["GPS"]["Location"]["Speed"]));
    // 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

Geolocation Testing (Legacy)
iOSDevice Object
GPS Property

Highlight search results