2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2015-07-15 19:45:40 +00:00
|
|
|
|
|
|
|
module Service
|
|
|
|
class GeoLocation
|
|
|
|
include ApplicationLib
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
lookup lat and lng for address
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = Service::GeoLocation.geocode('Marienstrasse 13, 10117 Berlin')
|
2015-07-15 19:45:40 +00:00
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = [ 4.21312, 1.3123 ]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.geocode(address)
|
|
|
|
|
|
|
|
# load backend
|
2016-01-14 09:39:52 +00:00
|
|
|
backend = load_adapter_by_setting('geo_location_backend')
|
2015-07-15 19:45:40 +00:00
|
|
|
return if !backend
|
|
|
|
|
|
|
|
# db lookup
|
|
|
|
backend.geocode(address)
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
lookup address for lat and lng
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = GeoLocation.reverse_geocode(4.21312, 1.3123)
|
2015-07-15 19:45:40 +00:00
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = 'some address'
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.reverse_geocode(lat, lng)
|
|
|
|
|
|
|
|
# load backend
|
2016-01-14 09:39:52 +00:00
|
|
|
backend = load_adapter_by_setting('geo_location_backend')
|
2015-07-15 19:45:40 +00:00
|
|
|
return if !backend
|
|
|
|
|
|
|
|
# db lookup
|
|
|
|
backend.reverse_geocode(lat, lng)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|