コード例 #1
0
        public PlaceEvent()
        {
            InitializeComponent();
            myMap.Focus();

            //Create custom pin for the users location
            Image userLocationPin = new Image();
            userLocationPin.Source = new BitmapImage(new Uri("images/userPin.png", UriKind.Relative));
            ToolTipService.SetToolTip(userLocationPin, "You are here");
            userLocationPin.Width = 20;
            userLocationPin.Height = 20;

            GeoLookup myGeoLookup = new GeoLookup();

            // Get host IP Address
            string myIP = new System.Net.WebClient().DownloadString("http://ipinfo.io/ip");

            // Turn IP Address into geo location lat & long
            myGeoLookup.GetGeo(myIP);

            // Right click to add pin method call
            myMap.MouseRightButtonDown += new MouseButtonEventHandler(Click_AddPins);

            //Wait for page load
            Loaded += onLoad;

            // users current position on map
            myMap.Center = new Location(Convert.ToDouble(myGeoLookup.Latitude), Convert.ToDouble(myGeoLookup.Longitude));
            //myMap.Center = new Location(52.792542056467, -6.14546695770263);

            // Map default zoom level 0-20
            myMap.ZoomLevel = 15;

            // Create new layer to hold pins
            MapLayer pinLayer = new MapLayer();

            //User Pin
            pinLayer.AddChild(userLocationPin, myMap.Center, PositionOrigin.Center);

            // Add pinlayer on top of maplayer
            myMap.Children.Add(pinLayer);
        }
コード例 #2
0
        public FindEvent(string eventType)
        {
            InitializeComponent();
            //Create custom pin for the users location
            Image userLocationPin = new Image();
            userLocationPin.Source = new BitmapImage(new Uri("images/userPin.png", UriKind.Relative));
            ToolTipService.SetToolTip(userLocationPin, "You are here");
            userLocationPin.Width = 20;
            userLocationPin.Height = 20;

            //Get host IP Address
            string myIP = new System.Net.WebClient().DownloadString("http://ipinfo.io/ip");

            //Turn IP Address into geo location lat & long
            GeoLookup myGeoLookup = new GeoLookup();
            myGeoLookup.GetGeo(myIP);
            userLat = Convert.ToDouble(myGeoLookup.Latitude);
            userLong = Convert.ToDouble(myGeoLookup.Longitude);

            //Testing stuff
            //Console.WriteLine("\nIPAddress: " + myIP + "Latitude: {0} \nLongitude {1}", myGeoLookup.Latitude, myGeoLookup.Longitude);
            //Console.WriteLine("Country {0} \ncity {1} \nregion: {2} \nipaddress: {3}", myGeoLookup.CountryName, myGeoLookup.CityName, myGeoLookup.RegionName, myGeoLookup.IpAddress);

            //Disable drag function
            myMap.MouseLeftButtonDown += Disable_Drag;

            //Disable zoom function
            myMap.MouseDoubleClick += Disable_Zoom;

            //Disable scroll function
            myMap.MouseWheel += Disable_MouseWheel;

            //Wait for page to load
            Loaded += onLoad;

            // Users current position on map
            myMap.Center = new Location(userLat, userLong);

            // Map default zoom level 0-20
            myMap.ZoomLevel = 15;

            // Create new layer to hold pins
            MapLayer pinLayer = new MapLayer();

            //User Pin
            pinLayer.AddChild(userLocationPin, myMap.Center, PositionOrigin.Center);

            try
            {
                //Online Connection Via FreeMySqlHosting.net
                String myConnection = "SERVER=sql2.freemysqlhosting.net;PORT=3306;DATABASE=sql292370;UID=sql292370;password=gA4*tV5%;";

                using (MySqlConnection myConn = new MySqlConnection(myConnection))
                {
                    myConn.Open();
                    string command = "";

                    // Event filter
                    switch (eventType)
                    {
                        case "default":
                            {
                                command = ("SELECT * FROM sql292370.Events WHERE (latitude BETWEEN " + userLat + " - .009 AND " + userLat + " + .009) && (longitude BETWEEN " + userLong + " - .012 AND " + userLong + " + .012) && (eventdate = CAST(NOW() AS DATE)) AND (CAST(NOW() AS TIME) < endtime) && (eventReport < 25);");
                                break;
                            }
                        case "sport":
                            {
                                command = ("SELECT * FROM sql292370.Events WHERE (latitude BETWEEN " + userLat + " - .009 AND " + userLat + " + .009) && (longitude BETWEEN " + userLong + " - .012 AND " + userLong + " + .012) && (eventdate = CAST(NOW() AS DATE)) AND (CAST(NOW() AS TIME) < endtime) && (eventGroup = 'Sport') && (eventReport < 25);");
                                break;
                            }

                        case "food":
                            {
                                command = ("SELECT * FROM sql292370.Events WHERE (latitude BETWEEN " + userLat + " - .009 AND " + userLat + " + .009) && (longitude BETWEEN " + userLong + " - .012 AND " + userLong + " + .012) && (eventdate = CAST(NOW() AS DATE)) AND (CAST(NOW() AS TIME) < endtime) && (eventGroup = 'Food') && (eventReport < 25);");
                                break;
                            }

                        case "other":
                            {
                                command = ("SELECT * FROM sql292370.Events WHERE (latitude BETWEEN " + userLat + " - .009 AND " + userLat + " + .009) && (longitude BETWEEN " + userLong + " - .012 AND " + userLong + " + .012) && (eventdate = CAST(NOW() AS DATE)) AND (CAST(NOW() AS TIME) < endtime) && (eventGroup = 'Other') && (eventReport < 25);");
                                break;
                            }
                        case "entertainment":
                            {
                                command = ("SELECT * FROM sql292370.Events WHERE (latitude BETWEEN " + userLat + " - .009 AND " + userLat + " + .009) && (longitude BETWEEN " + userLong + " - .012 AND " + userLong + " + .012) && (eventdate = CAST(NOW() AS DATE)) AND (CAST(NOW() AS TIME) < endtime) && (eventGroup = 'Entertainment') && (eventReport < 25);");
                                break;
                            }
                    }

                    MySqlCommand getEvents = new MySqlCommand(command, myConn);

                    using (MySqlDataReader DR = getEvents.ExecuteReader())
                    {

                        while (DR.Read())
                        {
                            //Create new pin
                            Pushpin pin = new Pushpin();

                            //set pin colour (based on group)
                            switch (DR.GetValue(12).ToString())
                            {
                                case "Sport":
                                    {

                                        pin.Background = new SolidColorBrush(Color.FromArgb(255, 77, 210, 0));
                                        break;
                                    }

                                case "Food":
                                    {
                                        pin.Background = new SolidColorBrush(Color.FromArgb(255, 255, 0, 17));
                                        break;
                                    }

                                case "Other":
                                    {
                                        pin.Background = new SolidColorBrush(Color.FromArgb(255, 255, 171, 0));

                                        break;
                                    }
                                case "Entertainment":
                                    {
                                        pin.Background = new SolidColorBrush(Color.FromArgb(255, 0, 26, 255));
                                        break;
                                    }
                            }

                            //Get and set pin location
                            pin.Location = new Location(DR.GetDouble(3), DR.GetDouble(4));

                            //Add pin tooltip (Event name)
                            ToolTipService.SetToolTip(pin, DR.GetValue(2));

                            //Add click event to pin
                            pin.MouseLeftButtonUp += Click_Pin;

                            //Add pin to pin layer
                            pinLayer.Children.Add(pin);

                            //Add all current event information to array
                            aList.Add(new Events(DR.GetValue(2).ToString(), DR.GetValue(8).ToString(), DR.GetDouble(3), DR.GetDouble(4), DR.GetTimeSpan(5), DR.GetTimeSpan(6), DR.GetDateTime(7), DR.GetInt16(9), DR.GetInt16(10), DR.GetInt16(0), DR.GetValue(11).ToString(), DR.GetValue(12).ToString()));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Add pinlayer on top of maplayer
            myMap.Children.Add(pinLayer);
        }