Module: Appium::Core::Base::HasLocation Private

Included in:
Driver
Defined in:
lib/appium_lib_core/common/base/has_location.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#location::Appium::Location

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the location of the device.

Examples:


driver.location #=> ::Appium::Location.new(10, 10, 10)

Returns:



30
31
32
# File 'lib/appium_lib_core/common/base/has_location.rb', line 30

def location
  @bridge.location
end

#location=(location) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the location of the device.

Examples:


driver.location = ::Appium::Location.new(10, 10, 10)

Parameters:



42
43
44
45
46
47
48
# File 'lib/appium_lib_core/common/base/has_location.rb', line 42

def location=(location)
  unless location.is_a?(::Appium::Location)
    raise TypeError, "expected #{::Appium::Location}, got #{location.inspect}:#{location.class}"
  end

  @bridge.set_location location.latitude, location.longitude, location.altitude
end

#set_location(latitude, longitude, altitude, speed: nil, satellites: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the location of the device.

Examples:


driver.location = ::Appium::Location.new(10, 10, 10)

Parameters:

  • latitude (String, Number)

    Set the latitude.

  • longitude (String, Number)

    Set the longitude.

  • altitude (String, Number)

    Set the altitude.

  • speed (String, Number) (defaults to: nil)

    Set the speed to apply the location on Android real devices in meters/second @since Appium 1.21.0 and in knots for emulators @since Appium 1.22.0.

  • satellites (String, Number) (defaults to: nil)

    Sets the count of geo satellites being tracked in range 1..12 @since Appium 1.22.0. This number is respected on Emulators.

  • (::Appium::Location)


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/appium_lib_core/common/base/has_location.rb', line 65

def set_location(latitude, longitude, altitude, speed: nil, satellites: nil)
  if speed.nil? && satellites.nil?
    self.location = ::Appium::Location.new(Float(latitude), Float(longitude), Float(altitude))
  else
    loc = ::Appium::Location.new(Float(latitude), Float(longitude), Float(altitude))

    speed = Float(speed) unless speed.nil?
    satellites = Integer(satellites) unless satellites.nil?

    @bridge.set_location loc.latitude, loc.longitude, loc.altitude, speed: speed, satellites: satellites
  end
end