Class: Api::V5::GoogleMapController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::GoogleMapController
- Defined in:
- app/controllers/api/v5/google_map_controller.rb
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#find_place_id ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/api/v5/google_map_controller.rb', line 2 def find_place_id lat = params.required(:lat) lng = params.required(:lng) url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&key=#{ENV['GOOGLE_MAP_API_KEY']}" response = DefaultFaradayClient.create_faraday_connection.get(url) results = JSON.parse(response.body)['results'] expires_in DEFAULT_HTTP_PUBLIC_CACHE_EXPIRATION, public: true if response.status == 200 && !results.empty? render json: { data: { place_id: results.first['place_id'] }, message: 'Success', success: true } else render json: { data: nil, message: 'Could not find place id', success: false } end rescue StandardError => e render json: { data: nil, message: e., success: false } end |