Class: GoogleMapsPlatform::GeolocationResponse

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/geolocation_response.rb

Overview

A successful geolocation request will return a JSON-formatted response defining a location and radius.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(location:, accuracy:, additional_properties: nil) ⇒ GeolocationResponse

Returns a new instance of GeolocationResponse.



47
48
49
50
51
52
53
54
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 47

def initialize(location:, accuracy:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @location = location
  @accuracy = accuracy
  @additional_properties = additional_properties
end

Instance Attribute Details

#accuracyFloat

The accuracy of the estimated location, in meters. This represents the radius of a circle around the given location. If your Geolocation response shows a very high value in the accuracy field, the service may be geolocating based on the request IP, instead of WiFi points or cell towers. This can happen if no cell towers or access points are valid or recognized. To confirm that this is the issue, set considerIp to false in your request. If the response is a 404, you’ve confirmed that your wifiAccessPoints and cellTowers objects could not be geolocated.

Returns:

  • (Float)


27
28
29
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 27

def accuracy
  @accuracy
end

#locationLatLngLiteral

An object describing a specific location with Latitude and Longitude in decimal degrees.

Returns:



16
17
18
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 16

def location
  @location
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 57

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  location = LatLngLiteral.from_hash(hash['location']) if hash['location']
  accuracy = hash.key?('accuracy') ? hash['accuracy'] : nil

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  GeolocationResponse.new(location: location,
                          accuracy: accuracy,
                          additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['location'] = 'location'
  @_hash['accuracy'] = 'accuracy'
  @_hash
end

.nullablesObject

An array for nullable fields



43
44
45
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 43

def self.nullables
  []
end

.optionalsObject

An array for optional fields



38
39
40
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 38

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



85
86
87
88
89
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 85

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} location: #{@location.inspect}, accuracy: #{@accuracy.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



78
79
80
81
82
# File 'lib/google_maps_platform/models/geolocation_response.rb', line 78

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} location: #{@location}, accuracy: #{@accuracy}, additional_properties:"\
  " #{@additional_properties}>"
end