Sha256: 2aba1ee03af6dcc06caf85398b5e85f94244f9cb09880bd598bbaef0dd4b5f70

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

Stored size: 869 Bytes

Contents

module MelissaData
  module GeoLookup
    module Geocoder
      extend self

      def address_to_coordinates(address)
        if authenticate
          lat_long = Geokit::Geocoders::GoogleGeocoder.geocode(address)
            .ll
            .split(",")
            .map(&:to_f)
            { latitude: lat_long.first, longitude: lat_long.last }
        end
      end

      def coordinates?(response)
        if !response[:errors] && !response[:property_address]&.empty?
          lat = response.fetch(:property_address)[:latitude]
          long =response.fetch(:property_address)[:longitude]
          lat != nil && long != nil
        else
          false
        end
      end

      def authenticate
        Geokit::Geocoders::GoogleGeocoder.api_key = MelissaData.google_maps_api_key
        Geokit::Geocoders::GoogleGeocoder.api_key
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
melissa_data-1.1.0 lib/melissa_data/geo_lookup/geocoder.rb
melissa_data-1.0.1 lib/melissa_data/geo_lookup/geocoder.rb
melissa_data-1.0.0 lib/melissa_data/geo_lookup/geocoder.rb