0

I working on an UWP (Win10) App with a simple location picker function. The user can drag the map on the wanted location. A basic Pushpin thats always in the center of the Map window acts as the location indicator. It works just like the free location pick in WhatsApp. To give the user feedback that he is moving the center pin, I want to raise the pin when the user is moving the map and lower it again on release.

Here the simple code to raise the pin (and manipulate the shadow):

private void MyMap_MapHolding(MapControl sender, MapInputEventArgs args)
    {
        iconSwitch = true;
        if(iconSwitch == true) {
            centerPin.Margin = new Thickness(0, 0, 0, 60);
            centerPinShadow.Opacity = 0.3;
            centerPinShadow.Width = 25;
     }

But this event doesn't seem to be affected on click & hold or tap & hold. Am I missing something?

FYI: I tried this out with the MyMap_MapTapped(...) method, and it worked just fine, but I need it when the map is dragged not just tapped.

Chees!

1 Answers1

0

I've tested and debugged, MapHolding event can't work by me either. For your purpose, CenterChangedLink event maybe helpful, I've tested it too.

Here is part of my sample code:

RandomAccessStreamReference mapIconStreamReference;
public Maptest()
{
    this.InitializeComponent();            
    myMap.Loaded += MyMap_Loaded;
    myMap.MapTapped += MyMap_MapTapped;
    myMap.MapHolding += MyMap_MapHolding;
    myMap.CenterChanged += MyMap_CenterChanged;
    mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/MapPin.png"));
}

private void MyMap_Loaded(object sender, RoutedEventArgs e)
{
    myMap.Center =
        new Geopoint(new BasicGeoposition()
        {
            //Geopoint for Seattle 
            Latitude = 47.604,
            Longitude = -122.329
        });
    myMap.ZoomLevel = 12;      

}

private void MyMap_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var tappedGeoPosition = args.Location.Position;
    string status = "MapTapped at \nLatitude:" + tappedGeoPosition.Latitude + "\nLongitude: " + tappedGeoPosition.Longitude;
    rootPage.NotifyUser( status, NotifyType.StatusMessage);
}

private void MyMap_MapHolding(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var holdingGeoPosition = args.Location.Position;
    string status = "MapHolding at \nLatitude:" + holdingGeoPosition.Latitude + "\nLongitude: " + holdingGeoPosition.Longitude;
    rootPage.NotifyUser(status, NotifyType.StatusMessage);
}

private void MyMap_CenterChanged(Windows.UI.Xaml.Controls.Maps.MapControl sender, object obj)
{
    MapIcon mapIcon = new MapIcon();
    mapIcon.Location = myMap.Center;
    mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
    mapIcon.Title = "Here";
    mapIcon.Image = mapIconStreamReference;
    mapIcon.ZIndex = 0;
    myMap.MapElements.Add(mapIcon);
}

At first I thought, even when the MapHoling event can't work, the Tapped action before holding should handled by MapTapped event, but it is seems this action is ignored. So remember, if a user hold the Map but not move it, nothing will happen.

panda
  • 560
  • 2
  • 10
  • That's what I figuered out, too, so far. I read some threads about Win 8.1 Apps with the map and many say that the emulators (Lokal Device or Phone Emu.) can't detect the left mouse button as a touch&hold event. I'll test _MapHolding with a Windows 10 phone of a collegue, soon. Will let you know if that's the issue. Thank you :) – ThatGuyNextDoor Nov 25 '15 at 15:40
  • http://www.sohua.xyz/questions/3050346/windows-8-bing-map-holding-event-doesnt-work-for-pc-mouse-but-works-fine-in-to – ThatGuyNextDoor Nov 25 '15 at 15:57
  • Really? Looking forward to your test's result. Thank you. – panda Nov 26 '15 at 01:08