Answer the question
In order to leave comments, you need to log in
Google Maps GeoDjango - No geometry value provided?
models.py:
from django.contrib.gis.db import models
class Location(models.Model):
name = models.CharField(max_length=100)
coords = models.PointField(null=True)
from django.contrib.gis import forms
class LocationForm(forms.ModelForm):
class Meta:
model = Location
fields = ['coords', 'name']
<div id="div_id_coords" class="form-group">
<div class="controls ">
<div id="id_coords_div_map">
<div id="id_coords_map"></div>
<span class="clear_features">
<a href="javascript:geodjango_coords.clearFeatures()">Delete</a>
</span>
<textarea id="id_coords" class="vSerializedField required" cols="150" rows="10" name="coords"></textarea>
<script type="text/javascript">
var map_options = {};
var options = {
geom_name: 'Point',
id: 'id_coords',
map_id: 'id_coords_map',
map_options: map_options,
map_srid: 4326,
name: 'coords'
};
var geodjango_coords = new MapWidget(options);
</script>
</div>
</div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?key=MY-KEY"></script>
{{ form.media }}
var map, marker, mapOptions = {...};
map = new google.maps.Map($('#id_coords_map')[0], mapOptions);
map.addListener('click', function(e){
placeMarker(e.latLng, map);
var position = marker.getPosition();
});
function placeMarker(latLng, map) {
marker = new google.maps.Marker({...});
return marker
}
Answer the question
In order to leave comments, you need to log in
You screw up your widget, but only for good, you need to send a string like POINT(lon,lat) to the server. And take it and see how it is in the built-in widget - there should be a hidden field
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question