Sha256: e3e73bacf605229b699da4cda0ff0baac711625970b2db9b0f7b3b738494e5f3

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

require "geomancer/version"

module Geomancer
  # Your code goes here...
  def self.configure(engine, opts={})
    @engine = engine
    @options = opts

    case @engine
    when :zip_code then
      require_relative './geomancer/zip_code'
    else
      require 'geocoder'
      Geocoder.configure(engine => opts)
    end
  end

  def self.geolocate address
    if !@engine
      warn("No configuration provided.  Defaulting to zip code geolocator")
      configure(:zip_code)
    end

    case @engine
    when :zip_code then
      Geomancer::ZipCode.geolocate(address)
    else
      address = address.gsub(/[\r\n]/,", ") # Yahoo doesn't like newlines
      results = Geocoder.search(address)
      return nil if results.empty?

      first_result = results.first
      {:latitude => first_result.latitude, :longitude => first_result.longitude}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geomancer-0.6.1 lib/geomancer.rb