M
M
ma3xak2018-07-16 18:28:17
Django
ma3xak, 2018-07-16 18:28:17

2gis + django how to implement?

Does anyone have experience integrating 2gis with djnago? How to implement this, each entry in the database should leave a marker on the map

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Kopitsa, 2018-07-16
@ma3xak

Make a model with the coordinate of the marker and add. information to display the icon.
If your database allows - I recommend using the gis extension (Geo Django)

from django.contrib.gis.db import models

class Marker(models.Model):
    point = models.PointField()
    icon_url = models.CharField(...)
    ...

If there is no opportunity to work with gis - use 2 fields lat/long
other attributes depending on the task.
In the template, in the drawing script, add each point in a loop.
<script type="text/javascript">
    var map;

    DG.then(function () {
        map = DG.map('map', {
            center: [54.98, 82.89],
            zoom: 13
        });

{% for marker in markers %}
        DG.marker([{{marker.point.x}}, {{marker.point.y}}]).addTo(map);
{% endfor %}

    });
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question