GeoDjango, which SRID to use to interact with PointField with the Google Maps V3 API?

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 
+8
django google-maps google-maps-api-3 postgis geodjango
source share
1 answer

You must use 4326 (which means latitude and longitude, using the WGS84 database and a spheroid to model the shape of the globe) to add points to Google Maps. Devices such as GPS, which record your position on the globe, will store data in 4326, which will then be projected inside Google Maps on 3857 (which is meters). If you look at the example for loading GeoJSON , you will see that the points are in 4326.

900913 (which is only GOOGLE in writing a calculator) caused a lot of confusion and came about because EPSG was originally very sniffy about what they consider an inaccurate projection, mainly because it assumes the world is a sphere. It has become popular anyway due to the global popularity of Google and its mathematical acceptability. Subsequently, EPSG gave it a new official designation of 3857 (well, technically, there was also another one, 3587, to cause even more confusion). So, while people are still talking about 900913, officially you should use 3587. 3587 is projected in meters and is used to create fragments for display on Google Maps, but should not be used to add point sources to it where you definitely want to use 4326.

There is a good article here if you want to know more about the history of this: http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/

+18
source share

All Articles