I am using django-rest-framework for the API, but when I make a post request sends me this error:
{
"location": [
"Invalid format: string or unicode input unrecognized as GeoJSON, WKT EWKT or HEXEWKB."
]
}
Body request:
{
"location":{
"type":"Point",
"coordinates":[37.0625,-95.677068]
}
}
My model is as follows:
class Address(models.Model):
location = geo.PointField(srid=4326, blank=True)
objects = geo.GeoManager()
My serializer is a follow:
class AddressCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Address
fields = ('location')
Help me please!
I use PointField
from django-extra-fields
for this. Supernice and intuitive for frontend developers (I write mobile backends mostly). With that, in your serializer specify:
from drf_extra_fields.geo_fields import PointField
class AddressCreateSerializer(serializers.ModelSerializer):
location = PointField()
class Meta:
model = Address
fields = ('location')
Request (taking a guess as to which of your values is lat and which is lon):
{
"location":{
"latitude": 37.0625
"longitude": -95.677068,
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With