Exemple #1
0
        private void PinCurrentPosition()
        {
            var currentPosition = new GeoCoordinate(App.ViewModel.CurrentPosition.Latitude, App.ViewModel.CurrentPosition.Longitude);

            marker = new UserLocationMarker() { GeoCoordinate = currentPosition };
            mapOverlay = new MapOverlay() { Content = this.marker, GeoCoordinate = currentPosition };

            var mapLayer = new MapLayer { this.mapOverlay };
            MyMap.Layers.Add(mapLayer);
        }
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/PhoneToolkitSample8;component/Samples/MapsSample.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.Map = ((Microsoft.Phone.Maps.Controls.Map)(this.FindName("Map")));
     this.RouteDirectionsPushPin = ((Microsoft.Phone.Maps.Toolkit.Pushpin)(this.FindName("RouteDirectionsPushPin")));
     this.StoresMapItemsControl = ((Microsoft.Phone.Maps.Toolkit.MapItemsControl)(this.FindName("StoresMapItemsControl")));
     this.UserLocationMarker = ((Microsoft.Phone.Maps.Toolkit.UserLocationMarker)(this.FindName("UserLocationMarker")));
 }
        public void ShowOnMap(double latitude, double longitude)
        {
            var geoPosition = new GeoCoordinate(latitude, longitude);
            myMap.SetView(geoPosition, 18, MapAnimationKind.Parabolic);

            mapOverlay = new MapOverlay();
            userMarker = new UserLocationMarker();
            mapOverlay.Content = userMarker;
            mapOverlay.GeoCoordinate = geoPosition;

            var mapLayer = new MapLayer { mapOverlay };
            myMap.Layers.Add(mapLayer);
        }
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/GPSWithFriends;component/MainPage.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.MyMap = ((Microsoft.Phone.Maps.Controls.Map)(this.FindName("MyMap")));
     this.FriendsLocationMarkerList = ((Microsoft.Phone.Maps.Toolkit.MapItemsControl)(this.FindName("FriendsLocationMarkerList")));
     this.MyLocationMarker = ((Microsoft.Phone.Maps.Toolkit.UserLocationMarker)(this.FindName("MyLocationMarker")));
     this.GPSLocationTextblock = ((System.Windows.Controls.TextBlock)(this.FindName("GPSLocationTextblock")));
     this.GroupNameTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("GroupNameTextBlock")));
     this.FriendsListBox = ((System.Windows.Controls.ListBox)(this.FindName("FriendsListBox")));
     this.InviteButton = ((System.Windows.Controls.Button)(this.FindName("InviteButton")));
     this.RequestsListBox = ((System.Windows.Controls.ListBox)(this.FindName("RequestsListBox")));
     this.FriendsManageListBox = ((System.Windows.Controls.ListBox)(this.FindName("FriendsManageListBox")));
 }
Exemple #5
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/GPSWithFriends;component/MainPage.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.MyMap      = ((Microsoft.Phone.Maps.Controls.Map)(this.FindName("MyMap")));
     this.FriendsLocationMarkerList = ((Microsoft.Phone.Maps.Toolkit.MapItemsControl)(this.FindName("FriendsLocationMarkerList")));
     this.MyLocationMarker          = ((Microsoft.Phone.Maps.Toolkit.UserLocationMarker)(this.FindName("MyLocationMarker")));
     this.GPSLocationTextblock      = ((System.Windows.Controls.TextBlock)(this.FindName("GPSLocationTextblock")));
     this.GroupNameTextBlock        = ((System.Windows.Controls.TextBlock)(this.FindName("GroupNameTextBlock")));
     this.FriendsListBox            = ((System.Windows.Controls.ListBox)(this.FindName("FriendsListBox")));
     this.InviteButton         = ((System.Windows.Controls.Button)(this.FindName("InviteButton")));
     this.RequestsListBox      = ((System.Windows.Controls.ListBox)(this.FindName("RequestsListBox")));
     this.FriendsManageListBox = ((System.Windows.Controls.ListBox)(this.FindName("FriendsManageListBox")));
 }
      // Sample code for building a localized ApplicationBar
      //private void BuildLocalizedApplicationBar()
      //{
      //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
      //    ApplicationBar = new ApplicationBar();

      //    // Create a new button and set the text value to the localized string from AppResources.
      //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
      //    appBarButton.Text = AppResources.AppBarButtonText;
      //    ApplicationBar.Buttons.Add(appBarButton);

      //    // Create a new menu item with the localized string from AppResources.
      //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
      //    ApplicationBar.MenuItems.Add(appBarMenuItem);
      //}

      private async void mapControl_Loaded(object sender, RoutedEventArgs e)
      {
         status.Text = "querying for current location...";

         Geolocator locator = new Geolocator();
         Geoposition geoPosition = await locator.GetGeopositionAsync();
         GeoCoordinate coordinate = geoPosition.Coordinate.ToGeoCoordinate();
         mapControl.Center = coordinate;
         mapControl.ZoomLevel = 10;

         position.Text = string.Format("Latitude: {0}\nLongitude: {1}\n",
             FormatCoordinate(coordinate.Latitude, 'N', 'S'),
             FormatCoordinate(coordinate.Longitude, 'E', 'W'));

         marker = new UserLocationMarker();
         marker.GeoCoordinate = coordinate;
         MapExtensions.GetChildren(mapControl).Add(marker);

         status.Text += "complete";
      }
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/7;component/MainPage2.xaml", System.UriKind.Relative));
     this.LayoutRoot                    = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.TitlePanel                    = ((System.Windows.Controls.StackPanel)(this.FindName("TitlePanel")));
     this.ApplicationTitle              = ((System.Windows.Controls.TextBlock)(this.FindName("ApplicationTitle")));
     this.MainMediaElement              = ((System.Windows.Controls.MediaElement)(this.FindName("MainMediaElement")));
     this.PivotControl                  = ((Microsoft.Phone.Controls.Pivot)(this.FindName("PivotControl")));
     this.ContentPanel                  = ((System.Windows.Controls.Grid)(this.FindName("ContentPanel")));
     this.XAMLMap                       = ((Microsoft.Phone.Maps.Controls.Map)(this.FindName("XAMLMap")));
     this.XAMLULMarker                  = ((Microsoft.Phone.Maps.Toolkit.UserLocationMarker)(this.FindName("XAMLULMarker")));
     this.StartAlarmButton              = ((System.Windows.Controls.Button)(this.FindName("StartAlarmButton")));
     this.CancelButton                  = ((System.Windows.Controls.Button)(this.FindName("CancelButton")));
     this.XAMLAutoCompleteBox           = ((Microsoft.Phone.Controls.AutoCompleteBox)(this.FindName("XAMLAutoCompleteBox")));
     this.DistanceLeftLabelTextBlock    = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLeftLabelTextBlock")));
     this.DistanceLeftDistanceTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLeftDistanceTextBlock")));
     this.miLabelTextBlock              = ((System.Windows.Controls.TextBlock)(this.FindName("miLabelTextBlock")));
     this.SettingsScrollViewer          = ((System.Windows.Controls.ScrollViewer)(this.FindName("SettingsScrollViewer")));
     this.RingerTextBlock               = ((System.Windows.Controls.TextBlock)(this.FindName("RingerTextBlock")));
     this.RingerSlider                  = ((System.Windows.Controls.Slider)(this.FindName("RingerSlider")));
     this.RingerTextBlockState          = ((System.Windows.Controls.TextBlock)(this.FindName("RingerTextBlockState")));
     this.VibrateTextBlock              = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateTextBlock")));
     this.VibrateSlider                 = ((System.Windows.Controls.Slider)(this.FindName("VibrateSlider")));
     this.VibrateTextBlockState         = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateTextBlockState")));
     this.DistanceLabelTextBlock        = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLabelTextBlock")));
     this.DistanceSettingSlider         = ((Microsoft.Phone.Controls.PhoneSlider)(this.FindName("DistanceSettingSlider")));
     this.DistanceSettingLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceSettingLabelTextBlock")));
     this.SoundSettingLabelTextBlock    = ((System.Windows.Controls.TextBlock)(this.FindName("SoundSettingLabelTextBlock")));
     this.SoundSettingButton            = ((System.Windows.Controls.Button)(this.FindName("SoundSettingButton")));
     this.VibrateSettingLabelTextBlock  = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateSettingLabelTextBlock")));
     this.VibrateSettingButton          = ((System.Windows.Controls.Button)(this.FindName("VibrateSettingButton")));
 }
        protected void MyGeolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (!MyCoordinates[0].Equals(new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude)))
                {
                    MyCoordinates[0] = new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
                    Map CSMap = (Map)FindName("XAMLMap");
                    CSMap.Center = MyCoordinates[0];
                    CSMap.ZoomLevel = 14;
                }
                else
                {
                    return;
                }

                CSULMarker = (UserLocationMarker)FindName("XAMLULMarker");
                CSULMarker.GeoCoordinate = MyCoordinates[0]; // works! 29 July 2014
                isCurrentLocationCenter = true;

                if (MyCoordinates[1] != null)
                {
                    distanceLeft = MyCoordinates[0].GetDistanceTo(MyCoordinates[1]) * 0.000621371; // distance calculator in meters, converted to miles
                    DistanceLeftDistanceTextBlock.Text = distanceLeft.ToString("0.00");
                    checkAlarm();
                }
            });
        }
        private async void GetCurrentCoordinates()
        {
            // Get the phone's current location.
            Geolocator MyGeolocator = new Geolocator();     // Main object to locate points
            if (MyGeolocator.LocationStatus == PositionStatus.Disabled || MyGeolocator.LocationStatus == PositionStatus.NotInitialized)
            {
                MessageBox.Show("Please enable Location Settings"
                    + "\nCommuter Buddy requires your location to function properly");
                // Location is turned off
                Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-location:"));
            }

            MyGeolocator.DesiredAccuracyInMeters = 5;
            MyGeolocator.MovementThreshold = 100; // in meters

            Geoposition MyGeoPosition = null;               // My Location
            try
            {
                MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));   // gets location
                MyCoordinates[0] = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
            }
            catch (Exception ex)
            {
                // Something else happened while acquiring the location.
                //MessageBox.Show(ex.Message + "\nAn Error Occured at Line 667 in MainPage.xaml.cs");
                MessageBox.Show(ex.Message + "\nPlease enable Location Settings");
                // Good Launcher!
                //Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-location:")); 
            }

            Map CSMap = (Map)FindName("XAMLMap");
            CSMap.Center = MyCoordinates[0];
            CSMap.ZoomLevel = 14;

            CSULMarker = (UserLocationMarker)FindName("XAMLULMarker");
            CSULMarker.GeoCoordinate = MyCoordinates[0]; // works! 29 July 2014
            isCurrentLocationCenter = true;

            MyGeolocator.PositionChanged += MyGeolocator_PositionChanged;
        }
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/7;component/MainPage2.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.TitlePanel = ((System.Windows.Controls.StackPanel)(this.FindName("TitlePanel")));
     this.ApplicationTitle = ((System.Windows.Controls.TextBlock)(this.FindName("ApplicationTitle")));
     this.MainMediaElement = ((System.Windows.Controls.MediaElement)(this.FindName("MainMediaElement")));
     this.PivotControl = ((Microsoft.Phone.Controls.Pivot)(this.FindName("PivotControl")));
     this.ContentPanel = ((System.Windows.Controls.Grid)(this.FindName("ContentPanel")));
     this.XAMLMap = ((Microsoft.Phone.Maps.Controls.Map)(this.FindName("XAMLMap")));
     this.XAMLULMarker = ((Microsoft.Phone.Maps.Toolkit.UserLocationMarker)(this.FindName("XAMLULMarker")));
     this.StartAlarmButton = ((System.Windows.Controls.Button)(this.FindName("StartAlarmButton")));
     this.CancelButton = ((System.Windows.Controls.Button)(this.FindName("CancelButton")));
     this.XAMLAutoCompleteBox = ((Microsoft.Phone.Controls.AutoCompleteBox)(this.FindName("XAMLAutoCompleteBox")));
     this.DistanceLeftLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLeftLabelTextBlock")));
     this.DistanceLeftDistanceTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLeftDistanceTextBlock")));
     this.miLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("miLabelTextBlock")));
     this.SettingsScrollViewer = ((System.Windows.Controls.ScrollViewer)(this.FindName("SettingsScrollViewer")));
     this.RingerTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("RingerTextBlock")));
     this.RingerSlider = ((System.Windows.Controls.Slider)(this.FindName("RingerSlider")));
     this.RingerTextBlockState = ((System.Windows.Controls.TextBlock)(this.FindName("RingerTextBlockState")));
     this.VibrateTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateTextBlock")));
     this.VibrateSlider = ((System.Windows.Controls.Slider)(this.FindName("VibrateSlider")));
     this.VibrateTextBlockState = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateTextBlockState")));
     this.DistanceLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceLabelTextBlock")));
     this.DistanceSettingSlider = ((Microsoft.Phone.Controls.PhoneSlider)(this.FindName("DistanceSettingSlider")));
     this.DistanceSettingLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("DistanceSettingLabelTextBlock")));
     this.SoundSettingLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("SoundSettingLabelTextBlock")));
     this.SoundSettingButton = ((System.Windows.Controls.Button)(this.FindName("SoundSettingButton")));
     this.VibrateSettingLabelTextBlock = ((System.Windows.Controls.TextBlock)(this.FindName("VibrateSettingLabelTextBlock")));
     this.VibrateSettingButton = ((System.Windows.Controls.Button)(this.FindName("VibrateSettingButton")));
 }