Class: Google::Cloud::Vision::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/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 "google/cloud/vision"

vision = Google::Cloud::Vision.new

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/google/cloud/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/google/cloud/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/google/cloud/vision/location.rb', line 43

def longitude
  @longitude
end

Class Method Details

.from_grpc(grpc) ⇒ Object



92
93
94
# File 'lib/google/cloud/vision/location.rb', line 92

def self.from_grpc grpc
  new grpc.latitude, grpc.longitude
end

Instance Method Details

#inspectObject



77
78
79
# File 'lib/google/cloud/vision/location.rb', line 77

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/google/cloud/vision/location.rb', line 58

def to_a
  [latitude, longitude]
end

#to_grpcObject



83
84
85
86
87
88
# File 'lib/google/cloud/vision/location.rb', line 83

def to_grpc
  Google::Type::LatLng.new(
    latitude: latitude,
    longitude: longitude
  )
end

#to_hHash

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

Returns:

  • (Hash)


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

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

#to_sObject



72
73
74
# File 'lib/google/cloud/vision/location.rb', line 72

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