Returns the shortest distance between two points such that the first point is part of g1 and the second of g2. The srid of g1 and g2 must be the same. If the srid is 4326, the haversine function is used to compute a great circle distance in kilometers on Earth. Otherwise the distance is calculated as on a flat Euclidean plane.