Class: CoreLocation::DataTypes::LocationCoordinate

Inherits:
Object
  • Object
show all
Defined in:
lib/map-kit-wrapper/core_location_data_types.rb

Overview

Ruby wrapper for CLLocationCoordinate2D

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LocationCoordinate

Initializer for LocationCoordinate

  • Args :

The initializer takes a variety of arguments

LocationCoordinate.new(1,2)
LocationCoordinate.new([1,2])
LocationCoordinate.new({:latitude => 1, :longitude => 2})
LocationCoordinate.new(LocationCoordinate)
LocationCoordinate.new(CLLocationCoordinate2D)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 32

def initialize(*args)
  args.flatten!
  self.latitude, self.longitude =
      case args.size
        when 1
          arg = args.first
          if arg.is_a? Hash
            [arg[:latitude], arg[:longitude]]
          else
            # For LocationCoordinate, CLLocationCoordinate2D
            [arg.latitude, arg.longitude]
          end
        when 2
          [args[0], args[1]]
      end
end

Instance Attribute Details

#latitudeObject

Attribute reader



18
19
20
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 18

def latitude
  @latitude
end

#longitudeObject

Attribute reader



18
19
20
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 18

def longitude
  @longitude
end

Instance Method Details

#apiObject

Returns the wrapped iOS CLLocationCoordinate2D object



51
52
53
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 51

def api
  CLLocationCoordinate2DMake(@latitude, @longitude)
end

#to_aObject

Get self as an Array

  • Returns :

    • [latitude, longitude]



81
82
83
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 81

def to_a
  [@latitude, @longitude]
end

#to_hObject

Get self as a Hash

  • Returns :

    • {:latitude => latitude, :longitude => longitude}



91
92
93
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 91

def to_h
  {:latitude => @latitude, :longitude => @longitude}
end

#to_sObject

Get self as a String

  • Returns :

    • "{:latitude => latitude, :longitude => longitude}"



101
102
103
# File 'lib/map-kit-wrapper/core_location_data_types.rb', line 101

def to_s
  to_h.to_s
end