Placing markers on Google Map With Django

后端 未结 1 1562
不知归路
不知归路 2021-02-02 04:33

I\'m trying to place markers based on the latitude and longitude stored in a model on a Google Map using the API and HTML5 geolocation.

The issue is how to loop through

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 04:36

    I use django-geoposition to manage my geodata

    from django.db import models
    from geoposition.fields import GeopositionField
    
    class Zone(models.Model):
        name = models.CharField(max_length = 50 )
        kuerzel = models.CharField(max_length = 3 )
        kn_nr = models.CharField(max_length = 5 )
        beschreibung = models.CharField(max_length = 300 )
        adresse = models.CharField(max_length = 100 )
        position = GeopositionField()
    

    view.py

    from geo.models import Zone
    from django.shortcuts import render_to_response, get_object_or_404, redirect
    
    def ShowZonen(request):
        zone=Zone.objects.all()
        return render_to_response('zonen.html', {"zone": zone})
    
    
    def showZoneDetail(request, zone_id):
        zone=Zone.objects.get(id=zone_id)
        return render_to_response('zonendetail.html', {"zone": zone})
    

    template zonendetail.html

    
    
    

    0 讨论(0)
提交回复
热议问题