Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tracker/models.py
- from django.db import models
- class Location(models.Model):
- date = models.DateTimeField(auto_now=True, auto_now_add=True)
- latitude = models.CharField(max_length=128)
- longitude = models.CharField(max_length=128)
- accuracy = models.CharField(max_length=128)
- def __unicode__(self):
- return str(self.latitude + "," + self.longitude + "," +self.accuracy)
- # tracker/views.py
- from django.http import HttpResponse
- from django.shortcuts import render_to_response
- from DJANGOPROJECT.tracker.models import Location
- def tracker(request, data):
- latitude = request.REQUEST["latitude"]
- longitude = request.REQUEST["longitude"]
- accuracy = request.REQUEST["accuracy"]
- newlocation = Location(latitude=latitude, longitude=longitude, accuracy=accuracy)
- newlocation.save()
- return HttpResponse("latitude: " + latitude + " longitude:" + longitude + " accuracy:" + accuracy, status=200, mimetype='text/plain')
- def find(request):
- l = Location.objects.all().order_by("-id")[0]
- print(l.date)
- return render_to_response('tracker/find.html', {'latitude': l.latitude, 'longitude': l.longitude, 'date': l.date})
- def plot(request):
- l = Location.objects.all().order_by("-id")[:20]
- centerLA = l[0].latitude
- centerLO = l[0].longitude
- return render_to_response('tracker/plot.html', {'locations': l, 'centerLA': centerLA, 'centerLO': centerLO })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement