private async Task AddToCollection()
        {
            StaticData._stationCollection = new ObservableCollection <StationTotal>();
            UTMConverter  utmConverter = new UTMConverter();
            MessageDialog msg          = new MessageDialog("Location Service is not available!", "Error");

            try
            {
                var pos = await _geolocator.GetGeopositionAsync();

                if (pos != null)
                {
                    Location            location = new Location(pos.Coordinate.Latitude, pos.Coordinate.Longitude);
                    LocationPointWithId a        = new LocationPointWithId();
                    a.latitude  = pos.Coordinate.Latitude;
                    a.longitude = pos.Coordinate.Longitude;
                    LocationPointWithId temp = new LocationPointWithId();

                    foreach (StationTotal b in StaticData._stationTotal)
                    {
                        utmConverter.ToLatLon(b.latitude, b.longitude, 48, 0);
                        temp.latitude  = utmConverter.Latitude;
                        temp.longitude = utmConverter.Longitude;

                        if (StaticMethod.Distance(a, temp) < StaticData.defaultDistance)
                        {
                            StaticData._stationCollection.Add(b);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageDialog messageDialog = new MessageDialog("Error: " + exception.Message);
                messageDialog.ShowAsync();
                //return;
            }
        }
        private void AddPushPin()
        {
            pushPin = new MapLayer();
            UTMConverter utmConverter = new UTMConverter();

            foreach (StationTotal temp in StaticData._stationCollection)
            {
                BusStationsPushPin pin = new BusStationsPushPin();
                utmConverter.ToLatLon(temp.latitude, temp.longitude, 48, 0);

                Location location = new Location(utmConverter.Latitude, utmConverter.Longitude);

                string pushPinContent = "";
                string busNumTemp     = "";

                foreach (Bus busTemp in temp.busList)
                {
                    if (busNumTemp != busTemp.busNumber)
                    {
                        pushPinContent = pushPinContent + " - " + busTemp.busNumber;
                        busNumTemp     = busTemp.busNumber;
                    }
                }

                pin.TextContent = pushPinContent;
                pin.Width       = double.NaN;
                pin.Tag         = temp;
                pin.Tapped     += pin_Tapped;

                pushPin.Children.Add(pin);

                MapLayer.SetPosition(pin, location);
            }

            map.Children.Add(pushPin);
        }
        private async Task AddToCollectionWithCustomLocation(Location location)
        {
            StaticData._stationCollection = new ObservableCollection <StationTotal>();
            UTMConverter utmConverter = new UTMConverter();

            LocationPointWithId a = new LocationPointWithId();

            a.latitude  = location.Latitude;
            a.longitude = location.Longitude;

            LocationPointWithId temp = new LocationPointWithId();

            foreach (StationTotal b in StaticData._stationTotal)
            {
                utmConverter.ToLatLon(b.latitude, b.longitude, 48, 0);
                temp.latitude  = utmConverter.Latitude;
                temp.longitude = utmConverter.Longitude;

                if (StaticMethod.Distance(a, temp) < StaticData.defaultDistance)
                {
                    StaticData._stationCollection.Add(b);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// StationInfo.xml - All Station Information - Each bus have 1 record in this Collection
        /// StaticData._busStationCollection
        /// </summary>
        private void LoadStationInfo()
        {
            UTMConverter utmConverter;

            StaticData._busStationCollection = new ObservableCollection <BusStationCollection>();

            if (!StaticData._busStationCollection.Any())
            {
                StaticData._busStationCollection = new ObservableCollection <BusStationCollection>();

                XDocument doc = XDocument.Load("Data/StationInfo.xml");

                BusStationCollection newBusStationCollection;
                foreach (var item in doc.Element("Stations").Elements("Stations"))
                {
                    newBusStationCollection = new BusStationCollection();

                    newBusStationCollection.id = item.Attribute("BusNum").Value;

                    foreach (var direction in item.Elements("Direction"))
                    {
                        if (direction.Attribute("go").Value == "1")
                        {
                            newBusStationCollection.goDirection = new ObservableCollection <BusStation>();

                            foreach (var station in direction.Elements("ID"))
                            {
                                utmConverter = new UTMConverter();
                                double tempLat = Convert.ToDouble(station.Element("latitude").Value);
                                double tempLon = Convert.ToDouble(station.Element("longitude").Value);

                                //Lat and Lon is in reverse order
                                utmConverter.ToLatLon(tempLon, tempLat, 48, 0);

                                BusStation newBusStation = new BusStation()
                                {
                                    id        = "[" + station.Attribute("id").Value + "]",
                                    number    = station.Element("number").Value,
                                    address   = "đường " + station.Element("address").Value,
                                    district  = "quận " + station.Element("district").Value,
                                    lat       = utmConverter.Latitude,
                                    lon       = utmConverter.Longitude,
                                    stationId = station.Element("stationId").Value,
                                };

                                newBusStationCollection.goDirection.Add(newBusStation);
                            }
                        }

                        if (direction.Attribute("go").Value == "0")
                        {
                            newBusStationCollection.backDirection = new ObservableCollection <BusStation>();

                            foreach (var station in direction.Elements("ID"))
                            {
                                utmConverter = new UTMConverter();
                                double tempLat = Convert.ToDouble(station.Element("latitude").Value);
                                double tempLon = Convert.ToDouble(station.Element("longitude").Value);
                                utmConverter.ToLatLon(tempLon, tempLat, 48, 0);

                                BusStation newBusStation = new BusStation()
                                {
                                    id        = "[" + station.Attribute("id").Value + "]",
                                    number    = station.Element("number").Value,
                                    address   = "đường " + station.Element("address").Value,
                                    district  = "quận " + station.Element("district").Value,
                                    lat       = utmConverter.Latitude,
                                    lon       = utmConverter.Longitude,
                                    stationId = station.Element("stationId").Value,
                                };

                                newBusStationCollection.backDirection.Add(newBusStation);
                            }
                        }
                    }

                    StaticData._busStationCollection.Add(newBusStationCollection);
                }

                //Enable Async
                //StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                //        "placeHolderData.dat", CreationCollisionOption.ReplaceExisting);
            }
        }