Exemplo n.º 1
0
Arquivo: views.py Projeto: lrvick/gmap
def showmap(request, address='', category=''):
    context = {}
    context['media_url'] = settings.MEDIA_URL

    if request.method == 'POST':
        address = request.POST.get('address', address)
        category = request.POST.get('category', category)
    if request.method == 'GET':
        address = request.GET.get('address', address)
        category = request.GET.get('category', category)

    if category:
        context['gmap_markers'] = MapMarker.objects.get(
                marker_type__category_name__iexact=category
                )
    else:
        context['gmap_markers'] = MapMarker.objects.all()

    if address:
        latlng = geolocate(address)
        if latlng:
            context['gmap_center_lat'] = latlng['latitude']
            context['gmap_center_lng'] = latlng['longitude']
        else:
            context['error'] = "Please try another address."

    return render(request, 'gmap.html', context)
Exemplo n.º 2
0
Arquivo: views.py Projeto: dpflug/gmap
def showmap(request, address='', category=''):
    context = {}
    context['media_url'] = settings.MEDIA_URL

    if request.method == 'POST':
        address = request.POST.get('address', address)
        category = request.POST.get('category', category)
    if request.method == 'GET':
        address = request.GET.get('address', address)
        category = request.GET.get('category', category)

    if category:
        context['gmap_markers'] = MapMarker.objects.get(
            marker_type__category_name__iexact=category)
    else:
        context['gmap_markers'] = MapMarker.objects.all()

    if address:
        latlng = geolocate(address)
        if latlng:
            context['gmap_center_lat'] = latlng['latitude']
            context['gmap_center_lng'] = latlng['longitude']
        else:
            context['error'] = "Please try another address."

    return render(request, 'gmap.html', context)
Exemplo n.º 3
0
    def save(self, *args, **kwargs):

        if not self.latitude and not self.longitude:
            full_address = "%s, %s, %s, %s, %s" % (self.address, self.city, self.state, self.zipcode, self.country)
            latlng = geolocate(repr(full_address))

            if latlng != None:
                self.latitude = latlng['latitude']
                self.longitude = latlng['longitude']

            else:
                raise GeolocateFailure("Failed to geolocate address for %s" % self.name, full_address )

        super(MapMarker, self).save(*args, **kwargs)
Exemplo n.º 4
0
    def save(self, *args, **kwargs):

        if not self.latitude and not self.longitude:
            full_address = "%s, %s, %s, %s, %s" % (self.address, self.city,
                                                   self.state, self.zipcode,
                                                   self.country)
            latlng = geolocate(repr(full_address))

            if latlng != None:
                self.latitude = latlng['latitude']
                self.longitude = latlng['longitude']

            else:
                raise GeolocateFailure(
                    "Failed to geolocate address for %s" % self.name,
                    full_address)

        super(MapMarker, self).save(*args, **kwargs)
Exemplo n.º 5
0
 def save(self, *args, **kwargs):
     latlng = geolocate(self.address)
     self.latitude = latlng['latitude']
     self.longitude = latlng['longitude']
     super(MapMarker, self).save(*args, **kwargs)