Get latitude and longitude from the address entered using gem geocoder
.
Get the Google API Key and display the map on the app.
It worked fine in the development environment, but in the production environment after deployment When I checked the operation, the map was not displayed for the address I entered and nothing was returned.
When I checked the console, it said No Apikeys
, ʻInvalidkey`, so I guess it was due to the API key.
Since I lacked knowledge of API, is there a problem with the code written in the development environment or a problem with the setting of Google API? I dig deeper thinking that, but I can't find any articles that could be solved.
By the way, I used gem" dotenv-rails "
for the API key, put it in the environment variable in .env
, and hid it in .gitignore
.
If you put in the Google Maps Platform API Checker, which is a Chrome extension, I was able to confirm that the error character and a sentence of the code containing the API key were displayed, but the API key itself was not found.
In other words, the environment variables have not been called.
When I googled around here, I could see that I was addicted to the swamp (laughs). I decided to calm down and think about it.
** ... Maybe it's because you're deploying to heroku? ?? ** **
So when I try to google, this is bingo!
** Heroku doesn't deploy files in .gitignore **
You said you need to set environment variables with heroku config: set
.
[heroku] Manipulating environment variables
I will refer to this article and set environment variables on heroku.
I was able to solve it safely! !! !!