Giter Site home page Giter Site logo

robertoallende / servicearea Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 288 KB

A proof of concept apps which allows you to draw a rectangle in a Google Map using Google Maps Api V3 and then add flags in a map. If the place is inside the area previously drawn, the flag will be green, otherwise red.

Python 29.26% JavaScript 65.38% CSS 5.37%

servicearea's Introduction

Servicearea

A proof of concept apps which allows you to draw a rectangle in a Google Map using Google Maps Api V3 and then add flags in a map. If the place is inside the area previously drawn, the flag will be green, otherwise red.

Test this application here. It was tested with Chrome v34 and v36.

Design and coding decisions

The key parts of this applications are:

  • A client coded in html, css and javascript using Google Maps Api V3.

  • A Django application with a shape model, which stores four coordinates, exposed via a REST API built with Django Rest Framework.

The html client is the result of merge of Google Maps API, therefore this application is not using any third party javascript framework such as Jquery, AngularJS or similar. Just plain Javascript. The html client uses the next Google Maps libraries:

  • Geolocation

  • Drawing

  • Places

Geolocations is used to detect the location of the user and based on that the map to be shown will be the place where the user is at the moment. If the user doesn't allow the browser to ask for the location, Aockland International Airport in California will be displayed as the default location. The maps location can be changed using the search box, this functionality is provided by Places library. The Drawing library is the one which provides the rectangle functionality.

When the rectangle is ready and the user clicks in submit, the rectangle coordinates are sent to the backend application. The four coordinates are saved on the backend and the browser will store a cookie with the url of the these coordinates, then the browser shows a new map and using the cookie's value the map will determinte the coordinates of the map to be shown and a 'hidden rectangle' which is the same drawn in the previous screen. If the user clicks 'inside' of the rectangle, the flag will be green. Otherwise red.

The second screen, coded in the defined-area.html and gmapwrapper-definedarea.js. These doesn't use any special Google Map Library, it just calculate where the click is made and if it fits with the coordinate.

The source code has comments with urls to the code reused, for futher details look there, along with the API sample, the code should be self descriptive, although it might require Google Maps api understanding.

The only third party being used besides Google Maps Api is the su3.js file, which implements a post and get method. Besides that, this application is mainly developed with plain javascript to focus just on Google Maps Api reuse and understanding.

Local Deployment

The application is made with Google App Engine API and Django. It can be deployed locally or in AWS.

  1. Create a directory for your project

    $ mkdir localdeploy

  2. Create a virtualenvironment, this is optional but recomended.

    $ cd localdeploy $ virtualenv python27 $ source python27/bin/activate

    If you get an error check if virtualenv is not installed. You can install it with 'sudo easy_install virtualenv'

  3. Clone the project

    $ git clone https://github.com/r0ver/servicearea.git

  4. Install Django and other required dependencies

    $ pip install -r requirements.txt

  5. Launch the app

    $ python manage.py syncdb $ python manage.py runserver

  6. Open the app in your browser, the default address should be localhost:8000

AWS Deployement

This application was tested with AWS using same Python and Django version described above. Follow all the steps described at Deploying a Django Application x ccto AWS Elastic Beanstalk Once you complete the tutorial, replace the django app created with this one.

servicearea's People

Contributors

robertoallende avatar

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.