• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Django model field that can hold a geoposition, and corresponding widget

django-geoposition

A model field that can hold a geoposition (latitude/longitude), and corresponding admin/form widget.

https://travis-ci.org/philippbosch/django-geoposition.svg?branch=master Join the chat at https://gitter.im/philippbosch/django-geoposition

Prerequisites

Starting with version 0.3, django-geoposition requires Django 1.8 or greater. If you need to support Django versions prior to 1.8 please use django-geoposition 0.2.3. For Django versions prior to 1.4.10 please use django-geoposition 0.1.5.

Installation

  • Use your favorite Python packaging tool to install geoposition from PyPI, e.g.:

    pip install django-geoposition
    
  • Add "geoposition" to your INSTALLED_APPS setting:

    INSTALLED_APPS = (
        # …
        "geoposition",
    )
    
  • Set your Google API key in you settings file:

    GEOPOSITION_GOOGLE_MAPS_API_KEY = 'YOUR_API_KEY'
    

    API keys may be obtained here: https://developers.google.com/maps/documentation/javascript/get-api-key

  • If you are still using Django <1.3, you are advised to install django-staticfiles for static file serving.

Usage

django-geoposition comes with a model field that makes it pretty easy to add a geoposition field to one of your models. To make use of it:

  • In your myapp/models.py:

    from django.db import models
    from geoposition.fields import GeopositionField
    
    class PointOfInterest(models.Model):
        name = models.CharField(max_length=100)
        position = GeopositionField()
    
  • This enables the following simple API:

    >>> from myapp.models import PointOfInterest
    >>> poi = PointOfInterest.objects.get(id=1)
    >>> poi.position
    Geoposition(52.522906,13.41156)
    >>> poi.position.latitude
    52.522906
    >>> poi.position.longitude
    13.41156
    

Form field and widget

Admin

If you use a GeopositionField in the admin it will automatically show a Google Maps widget with a marker at the currently stored position. You can drag and drop the marker with the mouse and the corresponding latitude and longitude fields will be updated accordingly.

It looks like this:

geoposition-widget-admin

Regular Forms

Using the map widget on a regular form outside of the admin requires just a little more work. In your template make sure that

  • jQuery is included
  • the static files (JS, CSS) of the map widget are included (just use {{ form.media }})

Example:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<form method="POST" action="">{% csrf_token %}
    {{ form.media }}
    {{ form.as_p }}
</form>

Settings

You can customize the MapOptions and MarkerOptions used to initialize the map and marker in JavaScript by defining GEOPOSITION_MAP_OPTIONS or GEOPOSITION_MARKER_OPTIONS in your settings.py.

Example:

GEOPOSITION_MAP_OPTIONS = {
    'minZoom': 3,
    'maxZoom': 15,
}

GEOPOSITION_MARKER_OPTIONS = {
    'cursor': 'move'
}

Please note that you cannot use a value like new google.maps.LatLng(52.5,13.4) for a setting like center or position because that would end up as a string in the JavaScript code and not be evaluated. Please use Lat/Lng Object Literals for that purpose, e.g. {'lat': 52.5, 'lng': 13.4}.

You can also customize the height of the displayed map widget by setting GEOPOSITION_MAP_WIDGET_HEIGHT to an integer value (default is 480).

License

MIT

More Repositories

1

haz

See at a glance which of the latest HTML5 and CSS3 features are supported in your browser
JavaScript
147
star
2

django-sirtrevor

A simple Django app that provides a model field and corresponding widget based on the fantastic Sir Trevor project
JavaScript
61
star
3

jquery-snappish

jQuery plugin for snappy scrolling of website sections
CoffeeScript
47
star
4

slack-webhook-cli

Send messages to Slack from the command line
Python
38
star
5

ical2json

Simple web service to convert iCal data from an URL to JSON output.
Python
23
star
6

ios-css

An extension for Compass that aims to provide Sass mixins for common iOS user interface elements
Ruby
23
star
7

django-werkzeug-debugger-runserver

Python
20
star
8

tailwindcss-hyphens

JavaScript
15
star
9

ng-shortcut

An Angular.JS directive to bind keyboard shortcuts to DOM elements
CoffeeScript
13
star
10

tailwind-swatches

JavaScript
10
star
11

tailwindcss-colorize

JavaScript
10
star
12

hyper-dark-macos

A theme for Hyperterm that pairs nicely with macOS dark mode
JavaScript
10
star
13

tailwindcss-selection-variant

Adds a variant for targeting user-selected text ranges (::selection) to Tailwind CSS.
JavaScript
9
star
14

django-tellafriend

Simple tell-a-friend functionality for Django-based websites
Python
8
star
15

tailwindcss-font-variant-numeric

A plugin for Tailwind CSS to create utility classes for font-variant-numeric.
JavaScript
8
star
16

django-campaignmonitor

A Django app to make it easier to create and manage newsletter campaigns and subscribers using Campaign Monitor. Status: very pre-alpha :)
Python
8
star
17

djangocon-mobile

JavaScript
7
star
18

ios-rubymotion-best-practices

JavaScript
7
star
19

django-rosetta

This repo is outdated. Please use the official repo at
Python
4
star
20

django-campaign

Unofficial fork of Arne Brodowski's django-campaign from Google Code
Python
4
star
21

django-sirtrevor-file

A file block for django-sirtrevor
JavaScript
4
star
22

yesno

Python
3
star
23

muto

A server and corresponding client library for ImageMagick-based image manipulation and conversion.
Python
2
star
24

python-whereby-api

Wrapper for the Whereby HTTP API
Python
2
star
25

hooktest

2
star
26

RadiateClient

Ruby
2
star
27

DieMauer

2
star
28

tailwind-ui-purge-css-example

HTML
2
star
29

aotp-jentsch

Website for Berlin-based electronic music god Jentsch.
JavaScript
2
star
30

dotfiles-legacy

my dotfiles
Python
2
star
31

jquery.mobile.ios7statusbar

CSS
1
star
32

muto-client

Python
1
star
33

slack-countdown

JavaScript
1
star
34

github-explorer

Demo project for a mobile app with sammy.js, mustache.js and some other stuff
JavaScript
1
star
35

isdjango1.3releasedyet.com

1
star
36

aotp-w32

Python
1
star
37

weatherhere

Location-aware weather app for iPhone
JavaScript
1
star
38

aotp-altendorfdsl

Python
1
star
39

jsconf-schedule

JavaScript
1
star
40

jqtouch-demos

JavaScript
1
star
41

anxiousprop

Python
1
star
42

cordova-osc-plugin

OSC Plugin for Apache Cordova / PhoneGap.
Objective-C
1
star
43

fabmap

Python
1
star
44

jekyll-slides

1
star
45

jsonp.pb.io

Python
1
star
46

lacmap-web

JavaScript
1
star
47

jekyll-skeleton

Ruby
1
star
48

svgqrcodes

No frills SVG QR Code generator
JavaScript
1
star
49

pburl

My personal short URL service
Python
1
star
50

keycoder

Ruby
1
star
51

leave-a-comment

JavaScript
1
star
52

jquery-morexpander

1
star
53

westostapp

Ruby
1
star
54

fancyflip

Ruby
1
star
55

touchsim

A very basic web-based iPhone simulator
JavaScript
1
star
56

tristyle

CoffeeScript
1
star
57

dokku-openscad

Shell
1
star
58

c2g

1
star
59

django-issuetracking

Simple issue tracking system based on Django
1
star
60

python-xbtesting

A Python library to talk to the API provided by CrossBrowserTesting.com
Python
1
star
61

newmediology

JavaScript
1
star
62

ireveal

Python
1
star
63

dokku-pre-release-command

Plugin for dokku that runs an app-specific script on each deploy
Shell
1
star
64

lsed

JavaScript
1
star
65

fhpmwa-animals

Demo project for HTML5 Web SQL databases for my course about Mobile Web Apps at FH Potsdam
JavaScript
1
star
66

fhpmwa

FH Potsdam «Mobile Web Apps für iPhone & Co.» SS 2010
JavaScript
1
star
67

jquery.mobile.heremap

HERE Maps widget for jQuery Mobile
JavaScript
1
star
68

aotp-theoffice

JavaScript
1
star
69

pb.io

TypeScript
1
star
70

slidenav

Ruby
1
star
71

fhpmwa-animals-couch

JavaScript
1
star
72

vanpey

1
star
73

img.pb.io

Python
1
star
74

cmstest

JavaScript
1
star
75

lastlyrics

JavaScript
1
star
76

django-admindashboard

Customizable dashboard for the django admin interface
1
star
77

refuge.io

refuge.io website
JavaScript
1
star
78

s3share

Simple sharing of files via S3
Python
1
star
79

ad-ade

A browser extension that replaces banner ads with … something else. Concept by Eike Theresa Stender, HfG Karlsruhe.
PHP
1
star
80

gitplayground

1
star
81

webapp-boilerplate

My boilerplate for universal web apps – including support for Compass, CoffeeScript, Less Framework, Add2Home, …
Ruby
1
star
82

jonnsonaguirre

Python
1
star
83

fhpmwa-tweets

Demo project for HTML5 localStorage for my course about Mobile Web Apps at FH Potsdam
JavaScript
1
star
84

philippbosch.github.com

JavaScript
1
star
85

cmsplugin-vimeovideo

Python
1
star
86

xbtests

JavaScript
1
star