Class: MapKit::DataTypes::CoordinateRegion

Inherits:
Object
  • Object
show all
Includes:
CoreLocation::DataTypes
Defined in:
lib/map-kit-wrapper/map_kit_data_types.rb

Overview

Wrapper for MKCoordinateRegion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CoordinateRegion

Initializer for CoordinateRegion

  • Args :

The initializer takes a variety of arguments

CoordinateRegion.new(CoordinateRegion)
CoordinateRegion.new(MKCoordinateRegion)
CoordinateRegion.new([56, 10.6], [3.1, 3.1])
CoordinateRegion.new({:center => {:latitude => 56, :longitude => 10.6},
                      :span => {:latitude_delta => 3.1, :longitude_delta => 3.1}}
CoordinateRegion.new(LocationCoordinate, CoordinateSpan)
CoordinateRegion.new(CLLocationCoordinate2D, MKCoordinateSpan)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 137

def initialize(*args)
  self.center, self.span =
      case args.size
        when 1
          arg = args[0]
          case arg
            when Hash
              [arg[:center], arg[:span]]
            else
              [arg.center, arg.span]
          end
        when 2
          [args[0], args[1]]
      end
end

Instance Attribute Details

#centerObject

Attribute reader



121
122
123
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 121

def center
  @center
end

#spanObject

Attribute reader



121
122
123
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 121

def span
  @span
end

Instance Method Details

#apiObject

Returns the wrapped iOS MKCoordinateRegion object

  • Returns :

    • A MKCoordinateRegion representation of self



159
160
161
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 159

def api
  MKCoordinateRegionMake(@center.api, @span.api)
end

#to_hObject

Get self as a Hash

  • Returns :

    • {:center => {:latitude => latitude, :longitude => longitude}, :span => {:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}}



189
190
191
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 189

def to_h
  {:center => @center.to_h, :span => @span.to_h}
end

#to_sObject

Get self as a String

  • Returns :

    • "{:center => {:latitude => latitude, :longitude => longitude}, :span => {:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}}"



199
200
201
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 199

def to_s
  to_h.to_s
end