Class: Decidim::GeolocationController

Inherits:
ApplicationController show all
Includes:
AjaxPermissionHandler
Defined in:
decidim-core/app/controllers/decidim/geolocation_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#default_locale?

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#locateObject



7
8
9
10
11
12
13
14
15
16
17
# File 'decidim-core/app/controllers/decidim/geolocation_controller.rb', line 7

def locate
  enforce_permission_to :locate, :geolocation

  unless Decidim::Map.configured?
    return render(json: { message: I18n.t("not_configured", scope: "decidim.application.geocoding"), found: false }, status: :unprocessable_entity)
  end

  geocoder = Decidim::Map.utility(:geocoding, organization: current_organization)
  address = geocoder.address([params[:latitude], params[:longitude]])
  render json: { address:, found: address.present? }
end