Giter VIP home page Giter VIP logo

django-google-maps's Introduction

django-google-maps

Basic example of how to use Google Maps with Django and PostGIS

Technologies

  • Django REST framework is a powerful and flexible toolkit for building Web APIs.

  • PostgreSQL is the World's Most Advanced Open Source Relational Database.

  • PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.

  • Geopy is a Python client for several popular geocoding web services.

  • Amazon S3: Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.

Requirements

  • Ubuntu 18

Installation

Clone this project:

git clone https://github.com/LegolasVzla/django-google-maps.git

Makefile will help you with all the installation. First of all, in django-google-maps/core/ path, execute:

make setup

This will install PostgreSQL, PostGIS and pip on your system. After that, you need to create and fill up settings.ini file, with the structure as below:

[postgresdbConf]
DB_ENGINE=django.contrib.gis.db.backends.postgis
DB_NAME=dbname
DB_USER=user
DB_PASS=password
DB_HOST=host
DB_PORT=port

[GEOSGeometryConf]
max_distance=5

[googleMapsConf]
API_KEY=yourGoogleAPIKey
defaultLat=<Your_default_latitude>
defaultLng=<Your_default_lingitude>

[amazonS3Conf]
S3_ACCESS_KEY=<Your_access_key>
S3_SECRET_KEY=<Your_secret_key>
s3_bucket_name=<Your_bucket_name>

[font-awesomeConf]
KEY=<Your_key>
  • postgresdbConf section: fill in with your own PostgreSQL credentials. By default, DB_HOST and DB_PORT in PostgreSQL are localhost/5432.

  • GEOSGeometryConf section: a max_distance suggested could be from 1-5 kilometers, to display nearby places.

  • googleMapsConf section: google maps API KEY needed to load the map, also a default lat and longitude to focus your map

  • font-awesomeConf section: optional, if you have a Font Awesome key for icons

Then, activate your virtualenv already installed (by default, is called env in the Makefile):

source env/bin/activate

And execute:

make install

This will generate the database with default data and also it will install python requirements and nltk resources. Default credentials for admin superuser are: [email protected] / admin.

Run django server (by default, host and port are set as 127.0.0.1 and 8000 respectively in the Makefile):

make execute

You could see the home page in:

http://127.0.0.1:8000/index/

The map will be setting in the defaultLat and defaultLng position.

Models

  • Spots: table to store places of the users. This table contains a position (PostGIS geometry) column that works to store information of latitude and longitude in WGS 84 format.
  • Tags: table to store tags related with the spots

Endpoints Structure for Spots API

In a RESTful API, endpoints (URLs) define the structure of the API and how end users access data from our application using the HTTP methods (GET, POST, PUT, DELETE), making all posssible CRUD (create, retrieve, update, delete) operations.

http://127.0.0.1:8000/api/spots/
Endpoint HTTP Method CRUD Method Result
api/<instance> GET READ Get all the record
api/<instance>/:id GET READ Get a single record
api/<instance> POST CREATE Create a new record
api/<instance>/:id PUT UPDATE Update a record
api/<instance>/:id DELETE DELETE Delete a record

Aditional Endpoints related with possible actions

Add a custom place (CREATE)

  • Endpoint path: api/spots/create_spot/

In "GoogleMaps" tab, you can create a new spot doing click in a position of the map and then doing click on the "Add Place" buttom: , fill up the form and save your spot. Also, you can create a several list of tags for you place.

Note: I used tagEditor plugin to create and edit tags, unfortunately this project is death but was the most recent jQuery tag editor that I could found.

See spots details (READ)

  • Endpoint path: api/spots/user_places/

In "My Spot List" tab, you can see all the details of your spot list.

Spot details (RETRIEVE)

  • Endpoint path: api/spots/spot_details/

In "My Spot List" tab, you can click on any spot and see the information related with it.

Edit spots (UPDATE)

  • Endpoint path: api/spots/edit_spot/

In "My Spot List" tab, you can edit spots by changging name or tags related with it.

Remove a place (DELETE)

  • Endpoint path: api/spots/delete_spot/

In "My Spot List" tab, you can delete a spot in the garbage icon. This action will delete the tags related with the spot if those tags doesn't exists for any other spot.

Nearby places

  • Endpoint path: api/spots/nearby_places/

In "GoogleMaps" tab, you can display nearby places from your current position within 'max_distance' in the nearby buttom: . The map will show your nearby places with the icon below:

Querying geometry data in PgAdmin4

Spots table contains two geometry columns in WGS 84 format (SRID 4326):

  • geom
  • position

That means that you can querying and watch our geometry data in PgAdmin4 as follow:

Now you can see an Eye Icon that means you can watch our data in the pgadmin map:

That's great! also you can watch it in differents layers (street, topography...)

Note: If our layers have an SRID other than 4326, the map will show the layers, but without a background.

Administrative Divisions

You can access of a administrative divisions data as below:

  1. Cities:

    administrative_area_level_1

  2. County, Municipality:

    administrative_area_level_2

  3. Parish:

    administrative_area_level_3

You can find more information about administrative divisions in:

Contributions


I started this project from yt-google-maps-1 repository and I could learn and fun myself at the same time :)

All work to improve performance is good

Enjoy it!

django-google-maps's People

Contributors

legolasvzla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-google-maps's Issues

configparser.NoSectionError: No section: 'googleMapsConf'

I faced an error at 'make install' step

configparser.NoSectionError:` No section: 'googleMapsConf'
`python3-tk is already the newest version (3.6.9-1~18.04).
The following packages were automatically installed and are no longer required:
  gir1.2-osmgpsmap-1.0 libosmgpsmap-1.0-1 linux-headers-5.4.0-66-generic linux-hwe-5.4-headers-5.4.0-64
  linux-hwe-5.4-headers-5.4.0-65 linux-hwe-5.4-headers-5.4.0-66 linux-image-5.4.0-66-generic
  linux-modules-5.4.0-66-generic linux-modules-extra-5.4.0-66-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
python manage.py makemigrations
Traceback (most recent call last):
  File "/usr/lib/python3.6/configparser.py", line 1138, in _unify_values
    sectiondict = self._sections[section]
KeyError: 'googleMapsConf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/emir/django-google-maps/core/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/emir/django-google-maps/core/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/home/emir/django-google-maps/core/env/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/emir/django-google-maps/core/env/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/emir/django-google-maps/core/env/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/emir/django-google-maps/core/core/settings.py", line 31, in <module>
    API_KEY = config.get('googleMapsConf', 'API_KEY')
  File "/usr/lib/python3.6/configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "/usr/lib/python3.6/configparser.py", line 1141, in _unify_values
    raise NoSectionError(section)
configparser.NoSectionError: No section: 'googleMapsConf'
Makefile:37: recipe for target 'install' failed
make: *** [install] Error 1
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.