How to find the midpoint between $2$ geographic coordinates (latitude, longitude)?

466 Views Asked by At

I have 2 geographic coordinates that I would like to find the midpoint to. For example:

Coordinate 1: $-37.756154,\ 145.147506$

Coordinate 2: $-37.754339, \ 145.143986$

After searching the internet and testing multiple functions, it seems like this is incredible difficult task.

Is there a function that can provide an accurate midpoint between $2$ coordinates with consistency across the globe or is it not possible?

EDIT: If there is an answer I would prefer it in programmatic syntax if possible:

fun midGeoPoint(lat1, lon1, lat2, lon2): GeoPoint {

    val dLon = Math.toRadians(lon2 - lon1)

    //convert to radians
    lat1 = Math.toRadians(lat1)
    lat2 = Math.toRadians(lat2)
    lon1 = Math.toRadians(lon1)

    val Bx = Math.cos(lat2) * Math.cos(dLon)
    val By = Math.cos(lat2) * Math.sin(dLon)
    val lat3 =
    Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By))
    val lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx)

    return lat3, lon3
} 
1

There are 1 best solutions below

1
On BEST ANSWER

It seems that your examples coordinates are very close to each other. In this case you can compute the midpoint the same way as if these where points in the plane. This means you are approximated the surface of the earth, which is a sphere, by a plane. This is only an approximation but for points close to each other the approximation is very good and depending on what you intend to do with it, this might be good enough and has the advantage of being very simple.

Edit: If your points are $(x_1, y_1)$ and $(x_2, y_2)$ (in geographic coordinates like you posted) that the approximate mid point would be the point $\left(\frac{x_1+x_2}{2}, \frac{y_1+y_2}{2}\right)$.