I am new to PostGIS, Spatial Reference Systems and projections and want to store lat/lng coordinates retrieved from Google Maps and its services like the Geocoder. I'm working with data in America and the main calculations are for nearest neighbors. Results will be plotted back on a web map (eg: via Google maps API or leaflet)

Question: What spatial reference system is Google map using? I figured out so far that its the WGS 84 datum with the Mercator projection in the geographic coordinate system. Should I store the location data as it is, or transform to US National Atlas Equal Area EPSG:2163?

Since I will be calculating distances and finding nearest neighbors, if I guess correctly that doing nearest neighbor search requires transforming the entire table to EPSG:2163, then will the solution be to store the data in both Mercator and EPGS:2163?


1 Answer 1


To get nearest neighbours you need to use lat/long and calculate the great-circle distance. For most purposes this C++ function, which assumes a spherical earth (the earth is not exactly a sphere) will be good enough:

/** Find the great-circle distance in metres, assuming a spherical earth, between two lat-long points in degrees. */
inline double GreatCircleDistanceInMeters(double aLong1,double aLat1,double aLong2,double aLat2)
    static const double KEquatorialRadiusInMetres = 6378137;

    aLong1 *= KDegreesToRadiansDouble;
    aLat1 *= KDegreesToRadiansDouble;
    aLong2 *= KDegreesToRadiansDouble;
    aLat2 *= KDegreesToRadiansDouble;

    double angle = acos(sin(aLat1) * sin(aLat2) + cos(aLat1) * cos(aLat2) * cos(aLong2 - aLong1));

    return angle * KEquatorialRadiusInMetres;
  • Although this (sort of) computes distances on the sphere, it's of little help in finding nearest neighbors.
    – whuber
    Apr 1, 2013 at 22:47
  • In fact it's a great help, because the concept 'nearest' implies a need for distance measurement. Dec 23, 2014 at 10:15
  • That's correct, Graham: but the real challenge is to develop an algorithm to find those nearest neighbors. Although the two objectives are obviously linked, the mere ability to calculate the distance only leads to brute-force solutions to limited questions involving point to point distances. Regardless, this issue (which is addressed in other threads) is tangential to the present question.
    – whuber
    Dec 23, 2014 at 14:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.