I'm a little confused that I need to set the SRID value in my GeoDjango PointField to stay accurate in the context of addresses geocoded via google maps api, in the coordinates and distances requested via django-postgis?
I get mixed opinions by reading streams around the network and the stack stream, and I'm not sure what to do. As you can see, my application uses geophysics with google api maps to geocode an address. Currently, there is no SRID set in my coordinate field, which is 4326 by default (EPSG: 4326). Now, apparently, it sees the Earth as a globe, not a flat surface.
According to the answer in the next question, things like google maps (EPSG 3857) are used, which apparently has SRID 900913. https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326 -for-googlemaps-openstreetmap-and-leaflet
So does this mean that I have to set my SRID to 900913? All coordinates of my restaurant model are stored in the same method as below using a geocoder. I would suggest so.
Now this is the place where they throw me away, the next tutorial http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html uses a dot field with the SRID set to 4326 (the default) and their marker points display perfectly on google maps.
My queries are decently accurate at the moment, but it still seems like this doesn't work a bit.
Help rate, 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
django google-maps google-maps-api-3 postgis geodjango
user3739703
source share