Skip to content

Commit

Permalink
Sync README.rst and docs/index.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
philippbosch committed May 20, 2014
1 parent 039e6a7 commit 0b37000
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 133 deletions.
47 changes: 34 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ A model field that can hold a geoposition (latitude/longitude), and correspondin
.. image:: https://pypip.in/v/django-geoposition/badge.png
:target: https://pypi.python.org/pypi/django-geoposition

.. image:: https://travis-ci.org/philippbosch/django-geoposition.png?branch=master
.. image:: https://travis-ci.org/philippbosch/django-geoposition.png?branch=master
:target: https://travis-ci.org/philippbosch/django-geoposition


Prerequisites
-------------

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


.. include:: ../README.rst

Installation
------------

Expand All @@ -35,7 +33,7 @@ Installation
"geoposition",
)

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


Expand All @@ -50,7 +48,7 @@ it:

from django.db import models
from geoposition.fields import GeopositionField

class PointOfInterest(models.Model):
name = models.CharField(max_length=100)
position = GeopositionField()
Expand All @@ -73,10 +71,10 @@ 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
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:
Expand All @@ -91,7 +89,7 @@ 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
- the static files (JS, CSS) of the map widget are included (just use
``{{ form.media }}``)

**Example**::
Expand All @@ -106,7 +104,28 @@ just a little more work. In your template make sure that
Settings
--------

At the moment there are no settings, but I should propably add some …
You can customize the `MapOptions`_ and `MarkerOptions`_ used to initialize the
map and marker in JavaScript by defining a ``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 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
Expand All @@ -115,10 +134,12 @@ License
`MIT`_



.. _PyPI: http://pypi.python.org/pypi/django-geoposition
.. _django-staticfiles: http://github.com/jezdez/django-staticfiles
.. _Google Maps: http://code.google.com/apis/maps/documentation/javascript/
.. |geoposition-widget-admin| image:: docs/images/geoposition-widget-admin.jpg
.. _jQuery: http://jquery.com
.. _MIT: http://philippbosch.mit-license.org/
.. _MapOptions: https://developers.google.com/maps/documentation/javascript/reference?csw=1#MapOptions
.. _MarkerOptions: https://developers.google.com/maps/documentation/javascript/reference?csw=1#MarkerOptions
.. _Lat/Lng Object Literals: https://developers.google.com/maps/documentation/javascript/examples/map-latlng-literal
120 changes: 0 additions & 120 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,121 +1 @@
.. include:: ../README.rst

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",
)

- 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 a ``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 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).



.. _PyPI: http://pypi.python.org/pypi/django-geoposition
.. _django-staticfiles: http://github.com/jezdez/django-staticfiles
.. _Google Maps: http://code.google.com/apis/maps/documentation/javascript/
.. |geoposition-widget-admin| image:: images/geoposition-widget-admin.jpg
.. _jQuery: http://jquery.com
.. _MapOptions: https://developers.google.com/maps/documentation/javascript/reference?csw=1#MapOptions
.. _MarkerOptions: https://developers.google.com/maps/documentation/javascript/reference?csw=1#MarkerOptions
.. _Lat/Lng Object Literals: https://developers.google.com/maps/documentation/javascript/examples/map-latlng-literal

0 comments on commit 0b37000

Please sign in to comment.