Answer the question
In order to leave comments, you need to log in
How to save marker coordinates from GoogleMap to GeoDjango model?
models.py:
class Location(models.Model):
name = models.CharField(max_length=100, verbose_name=u"Локация", default=u'')
coords = gis_models.PointField(u"долгота/широта", srid=4326, blank=True, null=True)
class LocationForm(forms.ModelForm):
class Meta:
model = Location
fields = ['name']
class AddLocationPageView(CreateView):
model = Location
form_class = LocationForm
template_name = 'add_location.html'
<form action="" method="POST">{% csrf_token %}
<div id="map-add-location" ></div>
<div class="col-md-5">
{{ form }}
<button type="submit">Add location</button>
</div>
</form>
$(document).ready(function(){
map = new google.maps.Map($('#map-add-location')[0], mapOptions);
map.addListener('click', function(e){
placeMarker(e.latLng, map);
var position = marker.getPosition();
});
var marker;
function placeMarker(latLng, map) {
marker = new google.maps.Marker({
position: latLng,
map: map,
});
return marker
}
});
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question