First of all thanks for making an awesome gem. It was so simple to get it working.
My code was working fine, but recently i started getting a frozen string error.
This is calling the distance matrix api. Implemented as a concern on a model called 'Address':
The error is thrown when calling the query:
Address.distance.query(origins: origin, destinations: dest, mode: 'driving', units: units)
Full concern code is this:
require 'googlemaps/services/client'
require 'googlemaps/services/distancematrix'
module Mappable
extend ActiveSupport::Concern
include GoogleMaps::Services
# https://maps.googleapis.com/maps/api/distancematrix/json?&key=
included do
client = GoogleClient.new(key: Rails.application.secrets.google_api_key, response_format: :json)
self.distance = DistanceMatrix.new(client) # creates a class instance variable (so this will be a singleton)
end
module ClassMethods
attr_accessor :distance
end
def distance_to(destination, units)
dest = []
origin = []
dest << {lat:"#{destination.latitude}", lng:"#{destination.longitude}"}
origin << {lat:"#{self.latitude}", lng:"#{self.longitude}"}
result = Address.distance.query(origins: origin, destinations: dest, mode: 'driving', units: units)
puts 'result is ****', result
return result['rows'][0]['elements'][0]['distance']
end
end
First of all thanks for making an awesome gem. It was so simple to get it working.
My code was working fine, but recently i started getting a frozen string error.
This is calling the distance matrix api. Implemented as a concern on a model called 'Address':
The error is thrown when calling the query:
Full concern code is this: