private void AddPushPin(MapControl map, double latitude, double longitude, Uri iconUri, GasStation gs, PriceColor priceColor, StationAccuracy stationAccuracy) { FuelStationPin pin = new FuelStationPin(); BitmapImage img = new BitmapImage(iconUri); pin.fuelStationLogo.Source = img; pin.fuelStationLogo.Tag = gs; pin.fuelStationLogo.Tapped += FuelStationLogo_Tapped; pin.fuelStationPrice.Text = gs.FT_PR + " €"; //Χρωματισμός των τιμών if (priceColor == PriceColor.Blue) { pin.fuelStationPrice.Foreground = new SolidColorBrush(Colors.Blue); } if (priceColor == PriceColor.Green) { pin.fuelStationPrice.Foreground = new SolidColorBrush(Colors.Green); } if (priceColor == PriceColor.Red) { pin.fuelStationPrice.Foreground = new SolidColorBrush(Colors.Red); } //Χρωματισμός του τριγώνου του pin if (stationAccuracy == StationAccuracy.Rooftop) { pin.fuelStationLabel.Source = new BitmapImage(new Uri("ms-appx:///Assets/PinLabels/marker_green.png")); } else { pin.fuelStationLabel.Source = new BitmapImage(new Uri("ms-appx:///Assets/PinLabels/marker_red.png")); } map.Children.Add(pin); var position = new Geopoint(new BasicGeoposition() { Latitude = latitude, Longitude = longitude }); MapControl.SetLocation(pin, position); MapControl.SetNormalizedAnchorPoint(pin, new Point(0.5, 1)); }
private async void FuelStationLogo_Tapped(object sender, TappedRoutedEventArgs e) { int numOfPins = int.Parse(gsNumLabel.Text.ToString()); //+1 γιατί υπάρχει και το pin της θέσης του χρήστη! numOfPins += 1; if (myMap.Children.Count > numOfPins) { myMap.Children.RemoveAt(myMap.Children.Count - 1); } Image img = (Image)sender; GasStation gs = (GasStation)img.Tag; // Ελεγχος σε τι συσκευή τρέχει για την εμφάνιση του ανάλογου infoBox var deviceType = CommonMethods.GetDeviceFamily(); if (deviceType == CommonMethods.DeviceFamily.Desktop) { //Τρέχει σε desktop InfoBoxDesktop infoBox = new InfoBoxDesktop(); infoBox.Name = "MyInfoBox"; infoBox.Margin = new Thickness(0, 0, 0, 60); infoBox.actions_grid.Tapped += Actions_grid_Tapped; infoBox.actions_grid.Tag = gs.LT + ", " + gs.LG; double maxmin25precent = (double)(maxPrice - minPrice) * 25 / 100; double price = Double.Parse(gs.FT_PR); if (price >= minPrice && price <= minPrice + maxmin25precent) { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Green); } else if (price <= maxPrice && price >= maxPrice - maxmin25precent) { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Red); } else { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Blue); } if (gs.AC == "ROOFTOP") { infoBox.gs_location_accuracy.Text = "Άριστη"; } else { infoBox.gs_location_accuracy.Text = "Μέτρια"; } infoBox.gs_fuel_type.Text = gs.FT; infoBox.gs_price.Text = gs.FT_PR + " €"; infoBox.gs_distance.Text = gs.DIS + " Km"; infoBox.gs_logo.Source = new BitmapImage(CommonMethods.GetFuelStationIcon(gs.BR_ID)); if (gs.BR == "ΑΝΕΞΑΡΤΗΤΟ ΠΡΑΤΗΡΙΟ") { infoBox.gs_name.Text = "ΑΠ"; } else if (gs.BR == "ΑΙΓΑΙΟ (AEGEAN)") { infoBox.gs_name.Text = "AEGEAN"; } else { infoBox.gs_name.Text = gs.BR; } infoBox.gs_owner.Text = gs.OW; infoBox.gs_address.Text = gs.AD; infoBox.gs_date.Text = gs.FT_DT; infoBox.gs_CloseBtn.Click += Gs_CloseBtn_Click; infoBox.gs_CloseBtn.Tag = infoBox; string phone1 = string.Empty; string phone2 = string.Empty; if (string.IsNullOrWhiteSpace(gs.PH1)) { phone1 = string.Empty; } else { phone1 = gs.PH1; } if (string.IsNullOrWhiteSpace(gs.PH2)) { phone2 = string.Empty; } else { phone2 = gs.PH2; } if (string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = "Μη διαθέσιμο"; } else { if (!string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH1 + ", " + gs.PH2; } if (!string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH1; } if (string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH2; } } double latitude = Double.Parse(gs.LT); double longitude = Double.Parse(gs.LG); myMap.Children.RemoveAt(myMap.Children.Count - 1); myMap.Children.Add(infoBox); var position = new Geopoint(new BasicGeoposition() { Latitude = latitude, Longitude = longitude }); MapControl.SetLocation(infoBox, position); MapControl.SetNormalizedAnchorPoint(infoBox, new Point(0.5, 1)); await myMap.TrySetViewAsync(position, 17); } else if (deviceType == CommonMethods.DeviceFamily.Mobile) { //Τρέχει σε κινητό InfoBox infoBox = new InfoBox(); infoBox.Name = "MyInfoBox"; infoBox.actions_grid.Tapped += Actions_grid_Tapped; infoBox.actions_grid.Tag = gs.LT + ", " + gs.LG; infoBox.Margin = new Thickness(0, 0, 0, 60); double maxmin25precent = (double)(maxPrice - minPrice) * 25 / 100; double price = Double.Parse(gs.FT_PR); if (price >= minPrice && price <= minPrice + maxmin25precent) { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Green); } else if (price <= maxPrice && price >= maxPrice - maxmin25precent) { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Red); } else { infoBox.gs_price.Foreground = new SolidColorBrush(Colors.Blue); } if (gs.AC == "ROOFTOP") { infoBox.gs_location_accuracy.Text = "Άριστη"; } else { infoBox.gs_location_accuracy.Text = "Μέτρια"; } infoBox.gs_fuel_type.Text = gs.FT; infoBox.gs_price.Text = gs.FT_PR + " €"; infoBox.gs_distance.Text = gs.DIS + " Km"; infoBox.gs_logo.Source = new BitmapImage(CommonMethods.GetFuelStationIcon(gs.BR_ID)); if (gs.BR == "ΑΝΕΞΑΡΤΗΤΟ ΠΡΑΤΗΡΙΟ") { infoBox.gs_name.Text = "ΑΠ"; } else if (gs.BR == "ΑΙΓΑΙΟ (AEGEAN)") { infoBox.gs_name.Text = "AEGEAN"; } else { infoBox.gs_name.Text = gs.BR; } infoBox.gs_owner.Text = gs.OW; infoBox.gs_address.Text = gs.AD; infoBox.gs_date.Text = gs.FT_DT; infoBox.gs_CloseBtn.Click += Gs_CloseBtn_Click; infoBox.gs_CloseBtn.Tag = infoBox; string phone1 = string.Empty; string phone2 = string.Empty; if (string.IsNullOrWhiteSpace(gs.PH1)) { phone1 = string.Empty; } else { phone1 = gs.PH1; } if (string.IsNullOrWhiteSpace(gs.PH2)) { phone2 = string.Empty; } else { phone2 = gs.PH2; } if (string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = "Μη διαθέσιμο"; } else { if (!string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH1 + ", " + gs.PH2; } if (!string.IsNullOrWhiteSpace(phone1) && string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH1; } if (string.IsNullOrWhiteSpace(phone1) && !string.IsNullOrWhiteSpace(phone2)) { infoBox.gs_phone.Text = gs.PH2; } } double latitude = Double.Parse(gs.LT); double longitude = Double.Parse(gs.LG); myMap.Children.RemoveAt(myMap.Children.Count - 1); myMap.Children.Add(infoBox); var position = new Geopoint(new BasicGeoposition() { Latitude = latitude, Longitude = longitude }); MapControl.SetLocation(infoBox, position); MapControl.SetNormalizedAnchorPoint(infoBox, new Point(0.5, 1)); await myMap.TrySetViewAsync(position, 17); } }
/// <summary> /// Εύρεση φθηνότερων πρατηρίων /// </summary> /// <param name="stations"></param> /// <returns></returns> public static List <GasStation> GetCheapestGasStetions(List <GasStation> stations) { List <GasStation> cheapest = null; double cheap1 = 1000; double cheap2 = 1000; double cheap3 = 1000; GasStation gs_1 = null; GasStation gs_2 = null; GasStation gs_3 = null; int i = -1; foreach (GasStation gs in stations) { i++; double price = double.Parse(gs.FT_PR); if (price < cheap1) { gs_1 = stations[i]; cheap1 = price; } } if (cheap1 != 1000) { //Εχουμε βρεί το φθηνότερο πάμε για το επόμενο int j = -1; foreach (GasStation gs in stations) { j++; double price = double.Parse(gs.FT_PR); if (price < cheap2 && price != cheap1) { gs_2 = stations[j]; cheap2 = price; } } } if (cheap1 != 1000 && cheap2 != 1000) { //Εχουμε βρεί τα δυο φθηνότερα πάμε για το τρίτο int x = -1; foreach (GasStation gs in stations) { x++; double price = double.Parse(gs.FT_PR); if (price < cheap3 && price != cheap1 && price != cheap2) { gs_3 = stations[x]; cheap3 = price; } } } if (gs_1 != null && gs_2 != null && gs_3 != null) { //Εχουν βρεθεί τα φθηνότερα αρα το προσθέτο στην λίστα και τα επιστέφω στο χρήστη cheapest = new List <GasStation>(); cheapest.Add(gs_1); cheapest.Add(gs_2); cheapest.Add(gs_3); return(cheapest); } else { return(null); } }