Skip to main content

Gather, store, and display real-time location information from Foursquare, iCloud, and more.

Project description


Do you check-in on Foursquare? Do you track your runs or bike commutes with Runmeter? Do you use an IOS device? Why let third-party interfaces be your only window into your day-to-day movements?

This Django application will consume location information provided by Foursquare, iCloud, and, if you happen to be a user of it, Runmeter, and store it in your database for display at will.


You can either install from pip:

pip install django-location

or checkout and install the source from the github repository:

git clone
cd django-location
python install

You’ll want to add both django-social-auth and django-location to your project’s; you can technically use whatever URL you’d like, but for the purposes of the instructions below, we’ll expect that you’ll add them like:

url(r'^location/', include('location.urls')),
url(r'', include('social_auth.urls')),

Location Sources

For some of the below consumers, iCloud and Runmeter specifically, you will need to set up a cron job that will handle certain periodic tasks, you can do this by adding a cron job running:

python /path/to/your/ location_consumer

I’d suggest running this at five or ten minute intervals, but selecting longer intervals will have only minor effects; either reducing sample frequency (in the case of the iCloud consumer) or increasing update latency (in the case of the Runmeter consumer).


Foursquare has options in its consumer settings to allow it to instantly post check-in information to an API endpoint that this application provides. To support that, you’ll need to do the following:

  1. Go to the Foursquare developer site and create a new consumer.

  2. Configure the following settings:

  3. Go to the configuration URL for the django-location app (usually while logged-in to the admin, and click on the ‘Authorize Foursquare’ button. This will bring you to Foursquare’s site using your configured options, and authorize your web application to receive check-ins from the user with which you log-into Foursquare.

  4. If everything is set-up, you shouldn’t need to do anything more, but Foursquare does offer a ‘Send a test push’ button on their consumer console that you can use to verify that everything is properly connected.


Runmeter does not provide an API, but does allow you to configure the application to send out e-mail notifications when you begin (and finish, etc) your run, bike, or anything else. To consume information from Runmeter, we’ll configure it to e-mail to an otherwise-unused e-mail inbox (important), and configure django-location to consume those e-mail messages and extract coordinates from the linked-to KML file.

  1. Configure the Runmeter application to send start and finish notifications to a mailbox accessible by POP3 or IMAP.
  2. Set-up Django Mailbox to consume mail from such a mailbox (consult django-mailbox’s documentation).
  3. Update users’ Location Consumer Settings record to set the field runmeter_email to match the e-mail address from which a user’s device will be sending Runmeter updates.


iCloud provides a service named ‘Find my iPhone’ that allows you to request your device’s location at-will. This library provides you with an easy way to use this service’s location information as one of your location sources.

  1. Identify the devices associated with your account, you can do that by using the list_icloud_devices management command:

    python /path/to/your/ list_icloud_devices <icloud username> <icloud password>

    replacing <icloud username> and <icloud password> with your iCloud username and password.

    This will print a list of devices and their IDs; in my case, it prints something like this:

    Name: MacBook Air 11": sinclair -- ID: reGYDh9XwqNWTGIhNBuEwP1ds0F/Lg5t/fxNbZ3V939hhXawByErk+HYVNSUzmWV
    Name: iPhone 4S: Adam Coddingtons iPhone -- ID: i9vbKRGIcLYqJnXMc1b257kUWnoyEBcEh6yM+IfmiMLh7BmOpALU+w==
  2. Update users’ Location Consumer Settings records to include the user’s iCloud username, iCloud password, and iCloud device ID from which you would like to gather location information.

Displaying Location Using a Template Tag

You can use the current_location template tag to gather the most recent location for a given user.

Simple example:

{% load current_location %}
{% current_location of 'adam' as location_of_adam %}

    {{ location_of_adam.user.username }} is at {{ location_of_adam.location.coords.1 }}, {{ location_of_adam.location.coords.0 }}

If you have installed ‘django-neighborhoods’ and ‘django-census-places’, you can also print city and neighborhood information:

{% load current_location %}
{% current_location of 'adam' as location_of_adam %}

    {{ location_of_adam.user.username }} is in the {{ }} neighborhood of {{ }}, {{ }}.

You might not always have neighborhood or city information for a given point, and maybe you would like to display a map using the Google Maps API; here’s a fleshed-out version:

{% load current_location %}
<script src="" type="text/javascript"></script>

{% current_location of 'somebody' as location %}
{{ location.user.username }} is
{% if location.neighborhood %}
    in the {{ }} neighborhood of {{ }},
    {{ location.neighborhood.state }}:
{% elif %}
    in {{ }}, {{ }}:
{% else %}
    ({{ location.get_nearest_city.distance.mi }} miles from {{ }}):
{% endif %}
<div id="my_location_map" style="width: 100%; height: 400px;"></div>
<script type="text/javascript">
    var myLocation = document.getElementById('my_location_map');
        'center': '{{ location.location.coords.1 }},{{ location.location.coords.0 }}',
        'zoom': 10,
        'mapTypeId': google.maps.MapTypeId.HYBRID
    myLocation.gmap('addMarker', {
        'position': '{{ location.location.coords.1 }},{{ location.location.coords.0 }}',
Bitdeli badge

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-location, version 2.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django-location-2.1.1.tar.gz (46.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page