【问题标题】:How to add MapIcon when clicked on MapControl in UWP app在 UWP 应用程序中单击 MapControl 时如何添加 MapIcon
【发布时间】:2021-09-08 07:55:15
【问题描述】:

我有一个地图控制元素 (XAML):

<Custom:MapControl 
           Name="MyMap"  
           Style="Terrain"                          
           ZoomInteractionMode="GestureAndControl"  
           TiltInteractionMode="GestureAndControl"    
           MapServiceToken="My key2" ZoomLevel="12"/>
    

我正在地图上放置一个带有已知纬度和经度数字的 MapIcon:

public void InitMap()
        {
            // Get position
            Geopoint Home = new Geopoint(new BasicGeoposition() { Latitude = 50, Longitude = 3 });
            // Create POI
            MapIcon myPOI_Home = new MapIcon { Location = Home, NormalizedAnchorPoint = new Point(0, 1.0), Title = "", ZIndex = 0 };
            myPOI_Home.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Home.png"));
            // Add to map and center it
            MyMap.MapElements.Add(myPOI_Home);
            MyMap.Center = Home;
            MyMap.ZoomLevel = 16;
            MyMap.LandmarksVisible = false;

        }

我希望在您单击地图时发生这种情况。因此,无论您在地图上单击什么位置,它都会将图标放置在这些坐标处。

有什么帮助吗?

【问题讨论】:

    标签: c# windows uwp bing-maps


    【解决方案1】:

    使用maps tapped event

    类似:

    MyMap.MapTapped += (object sender, MapInputEventArgs args) => {
        var loc = args.Location;
    
        //Add code to add your pin.
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 2016-02-08
      • 2021-05-27
      • 2018-12-28
      • 2015-02-22
      • 1970-01-01
      相关资源
      最近更新 更多