GetThereSafe is an application that uses the Google Maps Platform and the City of Victoria Open Data to map out the route with the most city lights.
The original application was created during nwHacks 2016. GetThereSafe won 1st prize for "Best Use of Data Analytics to Solve a Social Problem" during nwHacks 2016.
There is no live demo because Google Maps Platform no longer has a free tier, and pricing is too expensive for a developer making no income on an application.
By following the instructions below, you should be able to get a local copy working and be able to deploy your own instance of the GetThereSafe application with Heroku.
- Clone the repository on your local machine in your working directory and change into the
gettheresafe
directory.
cd working-directory
git clone [email protected]:FlyteWizard/gettheresafe.git
cd gettheresafe
- Install all the dependencies in
requirements.txt
.
pip install -r requirements.txt
# or
pip3 install -r requirements.txt
- Create a
.env
file based on.env.example
.
GOOGLE_API_KEY=
DATABASE_URL=
-
Create a Google Maps Platform Project. You will need to activate
Geocoding API
,Directions API
, andMaps JavaScript API
. -
Generate a frontend API Key with Google Maps Platform. This key will be what we use on the frontend and will need to be restricted.
-
Generate a backend API Key with Google Maps Platform. This key will be what we use on the backend, and should be kept secret.
-
Add your backend API Key to your
.env
file. ReplaceYOUR_SUPER_SECRET_API_KEY
with your backend API Key.
GOOGLE_API_KEY=YOUR_SUPER_SECRET_API_KEY
DATABASE_URL=
- Add your frontend API Key to the
index.html
file. ReplaceYOUR_NOT_SO_SECRET_API_KEY
with your frontend API Key.
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_NOT_SO_SECRET_API_KEY&callback=initMap" async defer></script> <!-- Google Map -->
-
Install Postgres App and Postgres CLI Tools.
-
Open and Initialize the Postgres App.
-
Start the Postgres App. You will need to Postgres App running when developing locally.
-
Create a local database with the Postgres App CLI. You can name the database anything you want, but we will name it
gettheresafe
.
createdb gettheresafe
- If you have new data points to add to
citylights.csv
you can add them and then runformatcsv.py
to format the new data points.
python formatcsv.py
# or
python3 formatcsv.py
- Populate local database with contents from
citylightsdb.csv
.
psql gettheresafe
CREATE TABLE coords (ID integer, LNG float, LAT float);
\copy coords FROM './citylightsdb.csv' WITH (FORMAT csv);
TABLE coords;
- Add your database URL to your
.env
file.
GOOGLE_API_KEY=YOUR_SUPER_SECRET_API_KEY
DATABASE_URL=postgresql:https://localhost/gettheresafe
- Run the app locally.
flask run
# or
python app.py
# or
python3 app.py
- Head over to https://127.0.0.1:5000/ to view your application.
-
Add access restrictions to your frontend API Key. This is important to prevent your API Key from being misused.
-
Create a new app on Heroku. Within your
gettheresafe
directory, run the following commands.
heroku create gettheresafe-username
- Add Heroku Postgres Add-on.
heroku addons:create heroku-postgresql:hobby-dev --app gettheresafe-username
- Add your local database to the Heroku Postgres database.
Run heroku pg:info --app gettheresafe-username
to find your database name. Replace [HEROKU_POSTGRESQL_MAGENTA]
with your Heroku Postgres database name.
heroku pg:push gettheresafe HEROKU_POSTGRESQL_MAGENTA --app gettheresafe-username
- Add your Heroku Postgres database URL to your Heroku config vars.
heroku pg:promote HEROKU_POSTGRESQL_MAGENTA --app gettheresafe-username
- Set your backend API Key in your Heroku config vars.
heroku config:set GOOGLE_API_KEY=YOUR_SUPER_SECRET_API_KEY --app gettheresafe-username
- Push app to Heroku.
git push heroku master
- Your app should be live at https://gettheresafe-username.herokuapp.com.