public void GetLocationsTest()
        {
            GeoQuerys target = new GeoQuerys(); // TODO: Initialize to an appropriate value
            Location pLocation = new Location("P1", double.Parse("52.2165425"), double.Parse("5.4778534")); // TODO: Initialize to an appropriate value
            int maxDistance = 10000; // TODO: Initialize to an appropriate value
            int maxResults = 100; // TODO: Initialize to an appropriate value
            SearchResults sr = new SearchResults();
            SearchResults actual;

            sr.StartSearch("52.2165425", "5.4778534", maxDistance.ToString(), maxResults.ToString());
            actual = target.GetLocations(pLocation, maxDistance, maxResults, sr);
            actual.EndSearch("");

            Assert.AreEqual(maxResults.ToString(), actual.maxResults);
        }
        /// <summary>
        /// Method to search locations close to other one 
        /// </summary>
        /// <param name="pLocation">Location</param>
        /// <param name="maxDistance">Max Distance</param>
        /// <param name="maxResults">Max number of Results</param>
        /// <returns></returns>
        public SearchResults GetLocations(Location pLocation, int maxDistance, int maxResults, SearchResults sr)
        {

            List<Location> filteredList = new List<Location>();
            SearchResults srDetailed = sr;
            try
            {
                //Get all Locations
                List<Location> lLocations = new List<Location>();
                using (GeoData gData = new GeoData())
                {
                    DateTime t1 = DateTime.UtcNow;

                    lLocations = gData.getAllLocations();
                    
                    DateTime t2 = DateTime.UtcNow;
                    TimeSpan t = t2 - t1;
                    double d = t.TotalSeconds;
                    srDetailed.ReadDataDuration = d;
                    srDetailed.FileRecords = lLocations.Count;
                }

                //Sort by Distance
                //Added Parallelism
                List<Location> SortedList = lLocations.AsParallel().WithDegreeOfParallelism(4).OrderBy(o => o.CalculateDistance(pLocation)).ToList();

                //Filter the Locations with the same Distance, Longitude and Latitude
                List<Location> filterRepeated = SortedList.AsParallel().WithDegreeOfParallelism(4).GroupBy(x => new { x.Distance, x.Longitude, x.Latitude })
                                                   .Select(g => g.First())
                                                   .ToList();

                //Filter by the max Number of Results
                filteredList = filterRepeated.Where(x => x.Distance <= maxDistance).Take(maxResults).ToList();
                srDetailed.Locations = filteredList;
            }
            catch(Exception ex)
            {
                throw ex;
            }

            return srDetailed;
        }
        public SearchResults GetLocations(string Latitude, string Longitude, string maxDistance, string maxResults)
        {
            ///I've implmented a class to register the Exceptions and traces of the application.
            ///This Trace class is connected with a 3rd Party System called franrodriguez.loggly.com

            using (Trace t = new Trace("SearchService", "GetLocations"))
            {
                using (SearchResults sr = new SearchResults())
                {
                    SearchResults srDetailed = new SearchResults();
                    try
                    {
                        //Start the Search
                        sr.StartSearch(Latitude, Longitude, maxDistance, maxResults);

                        //Lock the object to manage the interlocking of the request
                        lock (this.ThisLock)
                        {
                            //Call to the internal Controller to make the search
                            using (IGeoQuerys gq = new GeoQuerys())
                            {
                                Location location = new Location("P1", double.Parse(Latitude), double.Parse(Longitude));
                                srDetailed = gq.GetLocations(location, Int32.Parse(maxDistance), Int32.Parse(maxResults),sr);

                                //End the Search
                                srDetailed.EndSearch("");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        t.Error(e.Message.ToString(), e);
                        srDetailed.EndSearch(e.Message.ToString());
                    }

                    //Give back the json object
                    return srDetailed;
                }
            }
        }