Class: Gcloud::Vision::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/vision/location.rb

Overview

# Location

A latitude/longitude pair with values conforming to the [WGS84 standard](www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

image = vision.image "path/to/landmark.jpg"
entity = image.landmark

location = entity.locations.first

location.latitude #=> 43.878264
location.longitude #=> -103.45700740814209

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude, longitude) ⇒ Location

Returns a new instance of Location.



48
49
50
51
# File 'lib/gcloud/vision/location.rb', line 48

def initialize latitude, longitude
  @latitude  = latitude
  @longitude = longitude
end

Instance Attribute Details

#latitudeFloat

The degrees latitude conforming to the [WGS84 standard](www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).

Returns:

  • (Float)

    the current value of latitude



43
44
45
# File 'lib/gcloud/vision/location.rb', line 43

def latitude
  @latitude
end

#longitudeFloat

The degrees longitude conforming to the [WGS84 standard](www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf).

Returns:

  • (Float)

    the current value of longitude



43
44
45
# File 'lib/gcloud/vision/location.rb', line 43

def longitude
  @longitude
end

Class Method Details

.from_gapi(gapi) ⇒ Object



110
111
112
# File 'lib/gcloud/vision/location.rb', line 110

def self.from_gapi gapi
  new gapi.latitude, gapi.longitude
end

Instance Method Details

#inspectObject



95
96
97
# File 'lib/gcloud/vision/location.rb', line 95

def inspect
  "#<#{self.class.name} #{self}>"
end

#to_aArray

Returns the object’s property values as an array.

Returns:

  • (Array)


58
59
60
# File 'lib/gcloud/vision/location.rb', line 58

def to_a
  to_ary
end

#to_aryArray

Returns the object’s property values as an array.

Returns:

  • (Array)


67
68
69
# File 'lib/gcloud/vision/location.rb', line 67

def to_ary
  [latitude, longitude]
end

#to_gapiObject



101
102
103
104
105
106
# File 'lib/gcloud/vision/location.rb', line 101

def to_gapi
  Google::Apis::VisionV1::LatLng.new(
    latitude: latitude,
    longitude: longitude
  )
end

#to_hHash

Converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


76
77
78
# File 'lib/gcloud/vision/location.rb', line 76

def to_h
  to_hash
end

#to_hashHash

Converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


85
86
87
# File 'lib/gcloud/vision/location.rb', line 85

def to_hash
  { latitude: latitude, longitude: longitude }
end

#to_sObject



90
91
92
# File 'lib/gcloud/vision/location.rb', line 90

def to_s
  "(latitude: #{latitude.inspect}, longitude: #{longitude.inspect})"
end