Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
double normalize_angle(double base_angle, double angle) {
while (angle < base_angle) {
angle = angle + 360;
}
while (angle > base_angle + 360) {
angle = angle - 360;
}
return angle;
}
void main() {
double lon1 = 170.0, lon2=170.0;
double lon_extent = normalize_angle(0, lon2 - lon1);
double center_lon = normalize_angle(-180, lon1 + 0.5 * lon_extent);
printf(" center_lon = %f\n", center_lon);
}
Is it safe to say that your box will not contain a North or South poles (i.e., +/- 90 degrees lat)? I'll go with that for now. Certainly, it should be safe to assume that the poles are not interior to the box. (Possibly a pole could be on the horizontal edge of the box, but then we have to discuss the single point vs entire line caveat.)
Provided that both lats are in bounds (-90..+90), for the lat, you can simply use:
centerLat = (lat2 + lat1) / 2; (a rewrite of your function)
Even if the sum of the two lats is greater than 90, dividing by 2 brings it into bounds. So, for example, if two lats are 50 and 70, then 120 (is out of bounds), but 120/2 is 60 degrees latitude which is in bounds and is midway between the two lats. Keep in mind that in a mercator mapping, the north pole is represented by the top horizontal line; i.e. all the points on that top line represent a single point (north pole) on the sphere; so, as you get close to the north or south pole, the map will appear very distorted.
The long requires a little more explanation...