예제 #1
0
        public static List<Station> FromArray(List<string[]> data)
        {
            List<Station> stations = new List<Station>();

            foreach (string[] row in data)
            {
                // Convert string[] to class' fields.
                string postId = row[0];
                string postName = row[1];
                string street = row[2];
                float longitude = row[3] == @"\N" ? 0f : float.Parse(row[3], CultureInfo.InvariantCulture.NumberFormat);
                float latitude = row[4] == @"\N" ? 0f : float.Parse(row[4], CultureInfo.InvariantCulture.NumberFormat);

                // Add new row into DB.
                Station station = new Station(postId, postName, street, longitude, latitude);
                stations.Add(station);
            }

            return stations;
        }
예제 #2
0
        public Station[] GetNearestStations(double lat, double lng, int n)
        {
            Station[] nearestStations = new Station[n];
            double[] nearestStationsDistance = new double[n];

            // Fill distance arrays with MAX_DOUBLE.
            for (int i = 0; i < n; i++)
                nearestStationsDistance[i] = double.MaxValue;
            var maxDistancePosition = 0;
            var maxDistance = nearestStationsDistance[maxDistancePosition];

            // Search through database.
            for (int i = 0; i < Stations.Count; i++)
            {
                Station station = Stations[i];

                // Calculate distance from our position to station's position.
                double distance = GetDistance(lat, lng, station.latitude, station.longitude);

                // If found new nearest station.
                if (distance < maxDistance)
                {
                    // Copy station into array.
                     nearestStations[maxDistancePosition] = station;
                    nearestStationsDistance[maxDistancePosition] = distance;

                    // Find new max distance.
                    maxDistancePosition = 0;
                    maxDistance = nearestStationsDistance[maxDistancePosition];
                    for (int j = 0; j < n; j++)
                        if (nearestStationsDistance[j] > maxDistance)
                        {
                            maxDistance = nearestStationsDistance[j];
                            maxDistancePosition = j;
                        }
                }
            }
            
            return nearestStations;
        }
예제 #3
0
 public StationMarker(Station station, Marker marker)
 {
     _station = station;
     _marker = marker;
 }