private void MapWithPushpins_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            myMap.Children.Remove(currentPushpin);
            // Disables the default mouse double-click action.
            e.Handled = true;

            // Determin the location to place the pushpin at on the map.

            //Get the mouse click coordinates
            System.Windows.Point mousePosition = e.GetPosition(this);

            //Convert the mouse coordinates to a locatoin on the map
            var    pinLocation = myMap.ViewportPointToLocation(mousePosition);
            string test        = pinLocation.ToString();

            AddressResult ar = gh.GetAddress(test);

            cityTextBox.Text    = ar.Locality;
            addressTextBox.Text = ar.AddressLine;

            // The pushpin to add to the map.
            currentPushpin.Location = pinLocation;

            // Adds the pushpin to the map.
            myMap.Children.Add(currentPushpin);
        }
Exemple #2
0
 private async void DraggablePin_Tapped(object sender, TappedRoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (ClassInitializer.GetType() == typeof(DirectionsMainUserControl))
         {
             var Pointer = (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/InAppIcons/GMP.png")));
             if (DirectionsMainUserControl.Origin == null)
             {
                 DirectionsMainUserControl.Origin = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Origin",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer),
                 });
                 DirectionsMainUserControl.OriginAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
             else if (DirectionsMainUserControl.Destination == null)
             {
                 DirectionsMainUserControl.Destination = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Destination",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer)
                 });
                 DirectionsMainUserControl.DestinationAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
         }
         if (ClassInitializer.GetType() == typeof(SavedPlacesUserControl))
         {
             if (SavedPlacesUserControl.PName == string.Empty)
             {
                 await new MessageDialog("Specify a name for this place").ShowAsync();
             }
             else
             {
                 try
                 {
                     SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                     {
                         Latitude  = _map.Center.Position.Latitude,
                         Longitude = _map.Center.Position.Longitude,
                         PlaceName = SavedPlacesUserControl.PName
                     });
                 }
                 catch (Exception ex)
                 {
                     await new MessageDialog(ex.Message).ShowAsync();
                 }
             }
         }
     });
 }