2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://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
|