示例#1
0
 void MyMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
 {
     Bing.Maps.Location l = new Bing.Maps.Location();
     this.ControlMap.TryPixelToLocation(e.GetCurrentPoint(this.ControlMap).Position, out l);
     Bing.Maps.Pushpin pushpin = new Bing.Maps.Pushpin();
     pushpin.SetValue(Bing.Maps.MapLayer.PositionProperty, l);
     this.ControlMap.Children.Add(pushpin);
 }
        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var selecteditem = (pivotmainview.SelectedItem as ThumbnailImage);

            if (selecteditem != null)
            {
                var vm           = (App.Current.Resources["Locator"] as ViewModelLocator).Main;
                var bingLocation = new Bing.Maps.Location(selecteditem.GeoLocation.Position.Latitude, selecteditem.GeoLocation.Position.Longitude);
                vm.LocationTitle = selecteditem.ImageTitle;

                Frame.Navigate(typeof(ItemPage), bingLocation);
            }
        }
        private async void Location_Click(object sender, RoutedEventArgs e)
        {
            Windows.Devices.Geolocation.Geopoint position = await Shared.Position();

            Bing.Maps.Location location = new Bing.Maps.Location(position.Position.Latitude, position.Position.Longitude);
            UIElement          marker   = Shared.Marker();

            Display.Children.Add(marker);
            Bing.Maps.MapLayer.SetPosition(marker, location);
            Bing.Maps.MapLayer.SetPositionAnchor(marker, new Point(0.5, 0.5));
            Display.ZoomLevel = 12;
            Display.Center    = location;
        }
示例#4
0
        async public Task <String> ReverseGeocodePoint(Bing.Maps.Location l)
        {
            //return await ReverseGeocodeGoogle(l.Longitude, l.Latitude);

            string key = "AqzQTQg1GrHIoL2a5Ycf08czzcxAooMpXiADdOgZQYPBtwpuSSf8Fd4y7MUTJo-h";
            ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

            // Set the credentials using a valid Bing Maps key
            reverseGeocodeRequest.Credentials = new geocodeservice.Credentials();
            reverseGeocodeRequest.Credentials.ApplicationId = key;

            // Set the point to use to find a matching address
            geocodeservice.Location point = new geocodeservice.Location();

            point.Latitude  = l.Latitude;
            point.Longitude = l.Longitude;

            reverseGeocodeRequest.Location = point;

            // Make the reverse geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(geocodeservice.GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);

            // sometimes reverseGeocode is not getting me the right location so we will try to call the service a couple of times until it works, after a bit of tryouts we just return an error.
            int             numberOfTries   = 10;
            GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

            while (geocodeResponse.Results.Count == 0)
            {
                geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

                if (numberOfTries == 0)
                {
                    break;
                }
                numberOfTries--;
            }
            return(geocodeResponse.Results[0].Address.Locality);
        }
        private void ItemsListView_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            SelectionsMapLayer.Children.Clear();
            if (ItemsListView.SelectedItems.Count > 0)
            {
                if ((ListViewMode.MyGeofences == _currentListViewMode) || (ListViewMode.Places == _currentListViewMode))
                {
                    Bing.Maps.Location itemLocation = null;

                    // Add pushpins for all selected items
                    foreach (var item in ItemsListView.SelectedItems)
                    {
                        if (ListViewMode.MyGeofences == _currentListViewMode)
                        {
                            GeofenceItem g         = item as GeofenceItem;
                            Geocircle    geocircle = g.Geofence.Geoshape as Geocircle;
                            itemLocation = new Bing.Maps.Location(geocircle.Center.Latitude, geocircle.Center.Longitude);
                        }
                        else
                        {
                            Venue v = item as Venue;
                            itemLocation = new Bing.Maps.Location(v.Latitude, v.Longitude);
                        }

                        var pushPin = new Bing.Maps.Pushpin()
                        {
                            Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(100, 255, 23, 23)),
                        };
                        SelectionsMapLayer.Children.Add(pushPin);
                        Bing.Maps.MapLayer.SetPosition(pushPin, itemLocation);
                    }

                    // Center the map on the last seleced item
                    Map.SetView(itemLocation);
                }
            }
        }
示例#6
0
        void VendFinderApp_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
        {
            Bing.Maps.Location loc = new Bing.Maps.Location();
            this.VendFinderApp.TryPixelToLocation(e.GetCurrentPoint(this.VendFinderApp).Position, out loc);
            Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin();
            pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc);
            this.VendFinderApp.Children.Add(pushPin);



            // Add code to prompt user to enter VendMachine metadata...
            inputPrompt        = new TextBox();
            inputPrompt.Height = (1 / 4) * Height;
            inputPrompt.Width  = Width;
            inputPrompt.SetValue(Bing.Maps.MapLayer.PositionProperty, loc);
            inputPrompt.PlaceholderText = "Enter location of Vending Machine...";
            inputPrompt.IsEnabled       = true;
            inputPrompt.UpdateLayout();
            inputPrompt.Opacity    = 1;
            inputPrompt.Visibility = Visibility.Visible;
            VendFinderApp.Children.Add(inputPrompt);

            // Generic file name for file which stores user-prescribed location info.
            //string name = "database.txt";

            // Package the info file and save it to the user's system.
            //StorageFile storeFile =
            //  await storageFolder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName);

            mLoc = loc.Latitude.ToString() + "|" + loc.Longitude.ToString();

            //storeFile = await storageFolder.GetFileAsync("dataBase.txt");
            //await FileIO.WriteTextAsync(storeFile, loc.Latitude.ToString() + " " + loc.Longitude.ToString());

            pinBeingPlaced = true;
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            IHttpFilter filter = new AuthFilter(new HttpBaseProtocolFilter());

            _httpClient = new HttpClient(filter);

            _isConnectedToInternet = (null != NetworkInformation.GetInternetConnectionProfile());
            NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged;

            Logger.Initialize(LoggerTextBox, LoggerScrollViewer);
            await LogBackgroundEventsAsync();

            ShowStatus("Waiting for location...");

            try
            {
                _geolocator  = new Geolocator();
                _geoposition = await _geolocator.GetGeopositionAsync();

                ClearStatus();

                var position = _geoposition.Coordinate.Point.Position;
                Logger.Trace(TraceLevel.Info, String.Format("Current Location: {0}, Accuracy: {1} meters",
                                                            Logger.FormatLatLong(position.Latitude, position.Longitude),
                                                            _geoposition.Coordinate.Accuracy));

                // Initialize map
                var mapCenter = new Bing.Maps.Location(position.Latitude, position.Longitude);
                Map.SetView(mapCenter, Constants.DefaultMapZoomLevel);

                _currentLocationPushpin = new Bing.Maps.Pushpin();
                CurrentPositionMapLayer.Children.Add(_currentLocationPushpin);
                Bing.Maps.MapLayer.SetPosition(_currentLocationPushpin, mapCenter);

                // Register for position changed events
                _geolocator.PositionChanged += OnGeopositionChanged;

                // Loop through all background tasks to see if our background task is already registered
                foreach (var cur in BackgroundTaskRegistration.AllTasks)
                {
                    if (cur.Value.Name == _backgroundTaskName)
                    {
                        _geofenceTask = cur.Value;
                        break;
                    }
                }

                if (_geofenceTask != null)
                {
                    // Associate an event handler with the existing background task
                    _geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
                }
                else
                {
                    // Get permission for a background task from the user. If the user has already answered once,
                    // this does nothing and the user must manually update their preference via PC Settings.
                    var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

                    switch (backgroundAccessStatus)
                    {
                    case BackgroundAccessStatus.Unspecified:
                    case BackgroundAccessStatus.Denied:
                        ShowStatus("This application must be added to the lock screen in order to do automatic checkins.");
                        break;

                    default:
                        break;
                    }

                    // Register the background task.
                    var geofenceTaskBuilder = new BackgroundTaskBuilder();

                    geofenceTaskBuilder.Name           = _backgroundTaskName;
                    geofenceTaskBuilder.TaskEntryPoint = _backgroundTaskEntryPoint;

                    // Create a new location trigger
                    var trigger = new LocationTrigger(LocationTriggerType.Geofence);

                    // Associate the location trigger with the background task builder
                    geofenceTaskBuilder.SetTrigger(trigger);

                    // Ensure there is an internet connection before the background task is launched.
                    var condition = new SystemCondition(SystemConditionType.InternetAvailable);
                    geofenceTaskBuilder.AddCondition(condition);

                    // Register the background task
                    _geofenceTask = geofenceTaskBuilder.Register();

                    // Associate an event handler with the new background task
                    _geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

                    Logger.Trace(TraceLevel.Debug, "Background registration succeeded");
                }
            }
            catch (System.UnauthorizedAccessException)
            {
                ShowStatus("Location access denied, please go to Settings -> Permissions to grant this app access to your location.");
                Logger.Trace(TraceLevel.Warn, "Access denied when getting location");
            }
            catch (TaskCanceledException)
            {
                ShowStatus("Location acquisition was canceled. Close and re-launch this app if you would like to try again.");
                Logger.Trace(TraceLevel.Warn, "Canceled getting location");
            }
            catch (Exception ex)
            {
                Logger.Trace(TraceLevel.Error, "Could not acquire location or register background trigger: " + Logger.FormatException(ex));
            }

            Settings.Changed += OnSettingsChanged;
            Logger.Trace(TraceLevel.Info, "Foursquare query limit setting: " + Settings.QueryLimit + " places");
            Logger.Trace(TraceLevel.Info, "Geofence creation radius setting: " + Settings.GeofenceRadiusMeters + " meters");
        }
        private void ProcessCinemaInfo(Dictionary <int, CinemaInfo> currentCinemas, Dictionary <int, List <FilmInfo> > cinemaFilms, Dictionary <int, FilmInfo> Films, RegionDef region)
        {
            CineworldService cws      = new CineworldService();
            Cinemas          cinemas  = null;
            Task <Cinemas>   tcinemas = cws.GetCinemas(region, true);

            tcinemas.Wait();

            if (!tcinemas.IsFaulted && tcinemas.Result != null)
            {
                cinemas = tcinemas.Result;
            }

            CineMobileService mobileService = new CineMobileService();

            //foreach (var cinema in cinemas.cinemas)
            for (int i = 0; i < cinemas.cinemas.Count; i++)
            {
                //if (i > 1)
                //    break;

                var cinema = cinemas.cinemas[i];

                //if (cinema.id != 91)
                //    continue;

                Task <Films> tf = cws.GetFilms(region, false, cinema.id);

                Task <List <CinemaReview> > tReviews = mobileService.GetCinemaReviews(cinema.id);

                if (!currentCinemas.ContainsKey(cinema.id))
                {
                    CinemaInfo ci = new CinemaInfo()
                    {
                        Address   = cinema.address,
                        ID        = cinema.id,
                        Name      = cinema.name,
                        Postcode  = cinema.postcode,
                        Telephone = cinema.telephone
                    };

                    if (this.LatitudeDictionary.ContainsKey(cinema.id) && this.LongitudeDictionary.ContainsKey(cinema.id))
                    {
                        ci.Latitude  = this.LatitudeDictionary[cinema.id];
                        ci.Longitute = this.LongitudeDictionary[cinema.id];
                    }
                    else
                    {
                        Bing.MapsClient mapClient = new Bing.MapsClient("At7qhfJw20G5JptEm0fdIaMehzBAU6GT4jJRpznGY_rdPRa5NquCN5GP8bzzdG0d", "en-GB");
                        var             tLocation = mapClient.LocationQuery(
                            new Bing.Maps.Address()
                        {
                            AddressLine   = cinema.address,
                            PostalCode    = cinema.postcode,
                            CountryRegion = (region == RegionDef.GB ? "United Kingdom" : "Ireland")
                        });

                        tLocation.Wait();

                        Bing.Maps.Location location = null;

                        try
                        {
                            if (!tLocation.IsFaulted && tLocation.Result != null)
                            {
                                location = tLocation.Result.GetLocations().FirstOrDefault();
                            }
                        }
                        catch { }

                        if (location != null && location.Point != null && location.Point.Coordinates.Length == 2)
                        {
                            ci.Latitude  = location.Point.Coordinates[0];
                            ci.Longitute = location.Point.Coordinates[1];
                        }
                    }

                    tReviews.Wait();
                    if (!tReviews.IsFaulted && tReviews.Result != null)
                    {
                        ci.Reviews = tReviews.Result;
                    }

                    currentCinemas[cinema.id] = ci;
                }

                tf.Wait();

                if (!tf.IsFaulted && tf.Result != null)
                {
                    List <FilmInfo> cFilms = new List <FilmInfo>();
                    foreach (var film in tf.Result.films)
                    {
                        if (!Films.ContainsKey(film.edi))
                        {
                            continue;
                        }

                        FilmInfo fi = new FilmInfo()
                        {
                            EDI = film.edi, Title = film.CleanTitle
                        };
                        fi.ShowingToday = true;

                        cFilms.Add(fi);
                    }
                    cinemaFilms[cinema.id] = cFilms;
                }
            }
        }
示例#9
0
 private void Pin_Dragged(Bing.Maps.Location location)
 {
     CoordinatesTbx.Text = string.Format("{0:N5},{1:N5}", location.Latitude, location.Longitude);
 }
        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var selecteditem = (pivotmainview.SelectedItem as ThumbnailImage);
            if (selecteditem != null)
            {
                var vm = (App.Current.Resources["Locator"] as ViewModelLocator).Main;
                var bingLocation = new Bing.Maps.Location(selecteditem.GeoLocation.Position.Latitude, selecteditem.GeoLocation.Position.Longitude);
                vm.LocationTitle = selecteditem.ImageTitle;

                Frame.Navigate(typeof(ItemPage), bingLocation);
            }
        }
示例#11
0
        // This is the task which runs to load database information to the app.
        public void loadData()
        {
            List <string> machineNames     = new List <string>();
            List <double> machineCoordLat  = new List <double>();
            List <double> machineCoordLong = new List <double>();

            using (var queryContext = new VendingInfoContext())
            {
                try
                {
                    // Finish implementing database query system!
                    var machineEntities = queryContext.Machines.ToList();

                    // Organizes pin data from SQLite database into compartmentalized variables
                    // for use within the application.
                    for (int i = 0; i < machineEntities.Count(); i++)
                    {
                        machineNames.Add(machineEntities.ElementAt(i).machineName);

                        double tempLat  = double.Parse(machineEntities.ElementAt(i).machineLocation.Substring(0, 16));
                        double tempLong = double.Parse(machineEntities.ElementAt(i).machineLocation.Substring(17));
                        machineCoordLat.Add(tempLat);
                        machineCoordLong.Add(tempLong);
                    }

                    // Not sure if this actually helps with anything...
                    Debug.WriteLine(machineEntities[0].Id);
                }
                catch (Exception e)
                {
                    // Thrown if an exception occurs.
                    Debug.WriteLine("No elements in database at this time...: " + e);
                }
            }

            // Places all stored location pins onto the application's map.
            for (int i = 0; i < machineNames.Count(); i++)
            {
                Bing.Maps.Location loc = new Bing.Maps.Location(machineCoordLat.ElementAt(i), machineCoordLong.ElementAt(i));

                Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin();
                pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc);
                this.VendFinderApp.Children.Add(pushPin);

                // Add textbox containing location name to placed pin location...
                TextBox locText = new TextBox();
                locText.Height = (1 / 4) * Height;
                locText.Width  = Width;
                locText.SetValue(Bing.Maps.MapLayer.PositionProperty, loc);
                locText.Text      = machineNames.ElementAt(i);
                locText.IsEnabled = true;
                locText.UpdateLayout();
                locText.Opacity    = 1;
                locText.Visibility = Visibility.Visible;
                locText.IsReadOnly = true;
                VendFinderApp.Children.Add(locText);
            }

            //double lat = double.Parse(universalText.Substring(0, 16));
            //double longi = double.Parse(universalText.Substring(17));
            //Bing.Maps.Location loc = new Bing.Maps.Location(lat, longi);

            //Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin();
            //pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc);
            //this.VendFinderApp.Children.Add(pushPin);
        }