Google uses the Mercator projection, viewing the earth as an elongated cylinder. Thus, the task is to find the center of this projection.
For each lat / long pair, convert the x, y scale coordinates to the map (using radians):
x = long y = ln(tan(pi/4 + lat/2))
Then for x and y, find the average of the minimum and maximum to get your center. Convert back to lat / long as shown below.
Pseudo code center_long = average(minimum_x, maximum_x) center_lat = (atan(exp(average(minimum_y, maximum_y))) - pi/4)*2
The calculation of central longitude works great if it were not for the circular nature of the cylindrical projection of the Earth. If longitudes are in both the eastern and western hemispheres (some negative, some positive), additional work may be required.
Pseudo code sort the longitudes into ascending order for each longitude difference = longitude(i-1) - longitude(i) // for first, use longitude(0) - longitude(last) if (difference < 0) add 2*pi (360 degrees) Keep track of index of minimal difference The pair with the minimal difference represents the pair that most tightly contains all longitudes. Average this pair for the center longitude. If this pair was index 0 & last, add pi (180 degrees)
City result OP 4: (52.4 N, 7.0 E)
This is my second answer, because the first does not get the gist of the OP message. Since it has some value, it remains.
source share