Sha256: d17098f3a37e22592598775d227e2649995e278bde8b724af10d10e59c8d381f

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module CoreLocation
  # Wrappers for the Core Location Data Types
  # http://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html
  module DataTypes

    # Ruby wrapper for CLLocationCoordinate2D
    class LocationCoordinate
      attr_reader :sdk

      # LocationCoordinate.new(1,2)
      # LocationCoordinate.new([1,2])
      # LocationCoordinate.new(LocationCoordinate)
      # LocationCoordinate.new(CLLocationCoordinate2D)
      def initialize(*args)
        latitude, longitude = nil, nil
        args.flatten!
        if args.size == 1
          arg = args.first
          if arg.is_a?(CLLocationCoordinate2D)
            latitude, longitude = arg.latitude, arg.longitude
          elsif arg.is_a?(LocationCoordinate)
            latitude, longitude = arg.sdk.latitude, arg.sdk.longitude
          end
        elsif args.size == 2
          latitude, longitude = args[0], args[1]
        end
        @sdk = CLLocationCoordinate2DMake(latitude, longitude)
      end

      def latitude
        @sdk.latitude
      end

      def latitude=(latitude)
        @sdk.latitude = latitude
      end

      def longitude
        @sdk.longitude
      end

      def longitude=(longitude)
        @sdk.longitude = longitude
      end

      def to_array
        [latitude, longitude]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
map-kit-wrapper-0.0.2 lib/map-kit-wrapper/core_location_data_types.rb