Application link: https://rahulbethi.com/neighborhood_map
This is my Neighborhood map (web app), built by myself Rahul Bethi.
It shows some of the places I love in Bay area, California.
It uses Google Maps API to show a customized map, with my favorite places as markers on the map. Click the markers to get more info of the places. Google Street view near the place. Foursquare API is used to get more info about Cafés. All these places can be searched and filtered by category.
This app uses a PostgreSQL database and Python server to get the places in JSON format. It then processes this data and shows them as markers on the map.
- HTML, Javascript, Knockout JS v3.4.2 (organizational framework), Google Maps API v3.31, Foursquare API v2 20170801.
- Python v3.6.4 (web server), PostgreSQL v10.3 (database).
- Install database software - PostgreSQL v10.3.
- Install Python v3.6.4, and then
pip install
:flask
(microframework for Python)sqlalchemy
(Python SQL toolkit)
- Setup Database:
- Setup a database.
- I used pgAdmin 4 v2.1 which is installed along with PostgreSQL database software for Windows.
- Make a new json file named
secrets.json
indatabase_server
folder.- Fill out the JSON file with database name, username and password to access the database.
{ "postgresql": { "user": "USERNAME", "password": "PASSWORD", "database": "DATABASE_NAME" } }
- Fill out the JSON file with database name, username and password to access the database.
- Run
database_setup.py
using Python to setup the database with the Listing table. - Populate the database with values by running
init_values.py
using Python.
- Setup a database.
- Run
app.py
using Python, the app will be up and running on localhost:5000 address. Press Ctrl+C a couple of times to stop the server.- You can check the database server (python app) JSON output at http://localhost:5000/listings/json.
- Note: If you change the
server-address
(here) and JSON dataend-point
(here) in the web server (app.py
), you need to update it here (viewModel.js
) as well.
- Get a Google Maps API key and Foursquare API Client ID and Client Secret.
- For Google - Create a project and add Google Maps Javascript API and Google Street View Image API to your project.
- Make a new json file named
secrets.json
in theroot
folder.- Fill out the JSON file with the Google Maps API key and Foursquare API Client details.
{ "google": { "key": "GOOGLE_MAPS_API_KEY" }, "foursquare": { "client_id": "FOURSQUARE_API_CLIENT_ID", "client_secret": "FOURSQUARE_API_CLIENT_SECRET" } }
- Fill out the JSON file with the Google Maps API key and Foursquare API Client details.
- Open
index.html
.
-
PostgreSQL database is setup and stored with the data about my favourite places.
- Database can be accessed by Python (using SQLALchemy toolkit) using the
database name
,username
andpassword
located in thesecrets.json
file inside database_server folder. - Python file
database_setup.py
creates the 'Listing' table in the database.- Each place (column of table 'Listing') contains:
name
,category
, location (latitude
,longitide
), anddescription
.
- Each place (column of table 'Listing') contains:
init_values.py
python file adds some of my favorite places (in Bay area, California) to the 'Listings' table in the database.
- Database can be accessed by Python (using SQLALchemy toolkit) using the
-
Python web server (
app.py
) runs at localhost:5000.- It extracts the places from the database and sends back in JSON format at
http://localhost:5000/listings/json
.
- It extracts the places from the database and sends back in JSON format at
-
The Web-app (
index.html
) is our main app.- It calls two javascript files
init.js
andviewModel.js
.
- It calls two javascript files
-
The
init.js
Javascript file inititates the map and then calls the Knockout JS to bind with rest of the code, as everything is dependent on the Google Map.- It first extracts the API Keys from
secrets.json
JSON file in theroot
folder. - It then loads the Google Maps API script using the Google Maps API key in an asynchronous way.
- Knockout JS is setup after the Google Maps API is loaded.
- It first extracts the API Keys from
-
The
viewModel.js
Javascript file is the View-Model of the Knockout JS organizational framework with all the observational variables and bindings. It also has other functions and variables (Google Maps API, Foursquare API and search-filter features).- It requests the places data from the database sever we setup earlier.
- With the obtained JSON data, it creates 'places' objects with Google Maps API Markers.
- Categories of all the places are noted to filter out places with categories.
- It also has all other remaining variables and functions related to the functionality of the web-app.
-
Web-app consists a map with Markers of all the places. Each Marker is located at the
latitude
andlongitude
of it's place on the map. Web-app also has a 'Show Listings' button on the top-left corner. -
Markers: Clicking on each Marker on the map will open a small window with
name
, location (latitude
,longitude
) anddescription
of that marker's place.-
Google Street View -- Web app then requests the Google Street View Image API service to get the nearest 360 image and displays it in that window, when received.
-
Foursquare -- For cafés, there will be a button 'More info' in that window to search for Foursquare data about the café. Clicking that button will request Foursquare API Search for Venues service to search for the café with the
name
and location (latitude
,longitude
) of the café along with Foursquare category ID for cafe -4bf58dd8d48988d16d941735
. Received response (JSON) will have some details about the café along with itsvenue ID
.- Note: Not all places are available on Foursquare, a sorry message is displayed when a café is not found.
-
Using this
venue ID
, a different request is made to Foursquare API Venues service for more details. Received response (JSON) will have all the details about the café.website
,rating
,working hours
andFoursquare link
of the café are taken from the response and displayed.- Note: Not all places will have all the details.
-
Each Marker has three icons.
- Default icon - normal
- Highlighted icon - when mouse hovers over the marker.
- Selected icon - when the marked is clicked and info window is opened.
-
Drop-animation is played when a marker is shown after hiding them.
-
-
Listings side-bar (place's link): Clicking on the 'Show Listings' button will open a side-bar with all the place names as links. Here, the word Listing is used for a place's link.
- Clicking a Listing is same as clicking that place's Marker, but also closes the side-bar.
- The side-bar also has search feature to search for places and show the short-listed Listings. It has three elements.
- An input field to type the place name or category name.
- A drop-down menu to choose category - to filter out places with that category.
- Options of this menu is taken from the categories of all places.
- A 'Clear' button to clear the input field and reset drop-down menu to 'All' places.
- Listings can be scrolled up-down, if they don't fit in the page.
-
Search (filter): Search is done as you type, for each character or option selected.
- First, category drop-down menu (filter) is checked. 'All' option represents all places. Selecting any other category option will filter out places which are doesn't belong to that category.
- Next if the input field is not empty, then the input text is matched with the name of the places from category filter. Matched places are showed as Listings. Even Markers of unmatched places are removed from the map.
- Input is also matched with category names of places if the category filter is set to 'All'.
- Example: Typing in
cafe
will also match withStarbucks
as it is of same category (only when category filter is set to 'All').
- Example: Typing in
- Union of above two searches (place name search and category name search when category filter is set to 'All') is finally displayed as Listings.
- Special characters, spaces are ignored for convinience. All letters are converted to small-caps.
- Example: Typing in
suesgall
orsues gall
orsue'sGall
etc. will give same resultSue's Gallery Cafe
.
- Example: Typing in
- Even if the input is a middle word, it is matched.
- Example: Typing in
hwy
orh w y
etc. will give same resultCabrillo Hwy
andPanaromic Hwy
.
- Example: Typing in
-
Clicking anywhere on the map will close the info window of a place and also the side-bar (if it is open).
- If Google Maps API is not loaded - checks after 5 seconds of Google maps callback function
init_map()
. - If API Keys are not found in
secrets.json
file inroot
folder. - If both
secrets.json
files are not found or couldn't be accessed. - If database server couldn't be reached.
- If no places are present in the response from the database server. Database might be empty.
- Google Street View Image API service error inside info window of marker.
- Foursquare API Search for Venues service data fetching error.
- Foursquare API Venues service data fetching error.
- If no place was found while searching for Foursquare data.
- If no places (lisitngs) were found in the search (filter).
- Styling file
style.css
is incss
folder. - Images for Marker icons are in
images/marker_icons/flag
folder. - Screenshots are in
screenshots
folder. - Address to my hosted app: https://rahulbethi.com/neighborhood_map