地图图钉点击事件

本文关键字:事件 地图 | 更新日期: 2023-09-27 18:27:57

我正在构建一个windows phone 8.1应用程序,该应用程序读取一个文件(其中包含GPS点,每个点由例如纬度和经度字段组成)。对于每个点,我都有它,所以它在地图控件上显示一个小图钉图标,基于上面文件中的坐标。我有没有办法在图钉元素上实现点击事件,并使用它来显示另一个窗口,用户可以在其中更改/显示特定点/图钉信息(纬度或经度)?这是我用来读取我的文件并显示在地图上的东西,它工作得很好:

信息:notespublic ObservableCollection<Point> notes;

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        bool exist; // used to check if JSON file exists
        // get current position and set the map to point at it
        Geoposition position = await App.DataModel.GetCurrentPosition();
        await MyMap.TrySetViewAsync(position.Coordinate.Point, 16D);
        mySlider.Value = MyMap.ZoomLevel; // set it to 16D from previous line
        exist = await App.DataModel.FileExistsAsync();
        if (exist == true)
        {
            // read the file and load points into a list
            await App.DataModel.ReadFile();
            // put points on the map - little map icon
            foreach (var point in App.DataModel.notes)
            {
                MapIcon myMapIcon = new MapIcon();
                myMapIcon.Location = new Geopoint(new BasicGeoposition()
                {
                    Latitude = point.Latitude,
                    Longitude = point.Longitude,
                });
                myMapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
                MyMap.MapElements.Add(myMapIcon);
            }
        }
    }

地图图钉点击事件

不是您已经实现的,不是。如果您想要任何类型的最终用户事件,则需要使用MyMap.Children.Add(myXamlControl)而不是使用MyMap.MapElements.Add(myMapIcon)将基于XAML的图钉添加到映射中。MapIcons被集成到地图"图像"中,而不是浮在上面,并且不能对任何事情做出反应。

编辑:以下是如何为XAML控件设置点和锚点:

MyMap.SetLocation(myXamlControl, myPoint);
MyMap.SetNormalizedAnchorPoint(myXamlControl, new Point(0.5, 0.5));