Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate average latitude and longitude in C#

I have (minLatitude,maxLatitude) and (minLongitude,maxLongitude) pairs in decimal degrees, and I need to calculate the mean point of the box those pairs define, how can I get their average latitude/longitude? I get a pretty big offset when the simple arithmetic mean is calculated.

Thanks!

like image 574
Evenstar Avatar asked Dec 13 '22 09:12

Evenstar


1 Answers

The solution suggested by Pierre-Luc Champigny is wrong.

In the image bellow you can see two lines:

  1. (lat1,lon1) --> (lat2,lon2)
  2. (lat1,lon2) --> (lat2,lon1)

Half length of each line in green, the other half in blue.

You can see that the center of both lines is not the same point, and both centers are not the center of the polygon.

earth

In order to find the center of the polygon:

  • lat= avrg(lat1,lat2)
  • lon= avrg(lon1,lon2)

To get these values you can use the link suggested by Pierre-Luc Champigny, but:

  • Take the lat of the midpoint of (lat1,lon1) --> (lat2,lon1)
  • Take the lon of the midpoint of (lat1,lon1) --> (lat1,lon2)
like image 117
Lior Kogan Avatar answered Dec 28 '22 07:12

Lior Kogan