geo_location.rb 868 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. module Service
  3. class GeoLocation
  4. include ApplicationLib
  5. =begin
  6. lookup lat and lng for address
  7. result = Service::GeoLocation.geocode('Marienstrasse 13, 10117 Berlin')
  8. returns
  9. result = [ 4.21312, 1.3123 ]
  10. =end
  11. def self.geocode(address)
  12. # load backend
  13. backend = load_adapter_by_setting('geo_location_backend')
  14. return if !backend
  15. # db lookup
  16. backend.geocode(address)
  17. end
  18. =begin
  19. lookup address for lat and lng
  20. result = GeoLocation.reverse_geocode(4.21312, 1.3123)
  21. returns
  22. result = 'some address'
  23. =end
  24. def self.reverse_geocode(lat, lng)
  25. # load backend
  26. backend = load_adapter_by_setting('geo_location_backend')
  27. return if !backend
  28. # db lookup
  29. backend.reverse_geocode(lat, lng)
  30. end
  31. end
  32. end