I am a bit confused, what should I set my SRID value to in my GeoDjango PointField to stay accurate in the context of addresses being geocoded via google maps api into coordinates and distances being queried via django-postgis?
Im getting mixed opinions reading the threads around the net and stackover flow and am unsure what to do. As you can see my application is using geopy with google maps api to geocode an address. Right now my coordinates field doesn't have an SRID set which defaults to 4326 which is (EPSG: 4326). Now apparently this sees the earth as a globe, not a flat surface.
According to the answer in the following question things such as google maps use (EPSG 3857) which apparently has an SRID of 900913. https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet
So does this mean I should set my SRID to 900913? All my restaurant model's coordinates are saved in the same method seen below using the geocoder. I would assume so.
Now this is where I get thrown off, the following tutorial http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html uses a pointfield with their SRID set to 4326 (default) and their marker points appear perfectly on google maps.
Currently my queries are decently accurate but still feels seems a bit off.
Help is appreciated, thanks!
from geopy.geocoders import GoogleV3
from django.contrib.gis.geos import *
from django.contrib.gis.measure import D
geo = GoogleV3()
def home_page(request):
distance = 3680
address, coordinates = geo.geocode('Swanston Street, Melbourne Australia')
ref_location = Point(coordinates)
query = Restaurant.objects.filter(restaurant_location__distance_lte=(ref_location, D(m=distance))).distance(ref_location).order_by('distance')
return render(request, 'swings/home.html', {'restaurants': query})
Restaurant Model
class Restaurant(models.Model):
name = models.CharField(max_length=25, blank=False)
user = models.ForeignKey(User)
address = models.CharField(max_length=50, blank=False)
restaurant_location = models.PointField(null=False, blank=False)
objects = models.GeoManager()
def __str__(self):
return self.name