tags:

views:

27

answers:

2

Hi,

I have some code that batches addresses with 5 miles of each other. This is done by looping through a list of address and calculating the line of site distance between the first address and the remaining addresses. The first address in the list, along with any matching address are then put into another list.

Once I have the addresses batched, I want to be abe to calculate the centre of the batch. At the moment I'm using the first address, however I would like some better accuracy. As I have the lat/lon's can I use a mathematical function for this?

Mark

+1  A: 

The "center" would be (I believe) the average of the highest & lowest latitute and the highest and lowest longitute.

   var hilat = list.Max(loc=>loc.Latitute);
   var lolat = list.Min(loc=>loc.Latitute);
   var hilng = list.Max(loc=>loc.Longitute);
   var lolng = list.Min(loc=>loc.Longitute);

   var center = new Location() { Latitute = (hilat-lolat)/2 + lolat, 
                                 Logitute = (hilng-lolng)/2 + lolng};
James Curran
+3  A: 

The center would be the average of all locations :

var center = new Location
             {
                 Latitude = list.Average(loc => loc.Latitude),
                 Longitude = list.Average(loc => loc.Longitude)
             };
Thomas Levesque