地图图钉点击事件 [英] Map pushpin click event

查看:138
本文介绍了地图图钉点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Windows Phone 8.1应用程序,该应用程序读取一个文件(该文件包含GPS点,每个点都包含例如纬度和经度字段).对于每个点,我都会根据上面文件中的坐标将其显示在地图控件上,并带有一个小图钉图标.有什么办法可以在图钉元素上实现click事件并将其用于例如显示另一个窗口,用户可以在其中更改/显示特定的点/图钉信息(纬度或经度)?这就是我用来读取文件并在地图上显示的内容,并且效果很好:

I'm building a windows phone 8.1 app that reads a file ( which holds GPS points, each point consists of e.g. latitude and longitude fields). For each point I have it so it's displayed with a little pushpin icon on the map control, based on its coordinated from the above file. Is there any way I can implement a click event on the push pin element and use it to e.g. to display another window where user can change/display specific point/pushpin info ( latitude or longitude) ? This is what I use to read my file and display on the map and it works fine:

信息: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集成到地图的图像"中,而不是漂浮在顶部,并且不能对任何东西做出反应.

Not as you have implemented, no. You will need to add XAML-based pushpins to the map using MyMap.Children.Add(myXamlControl) instead of using MyMap.MapElements.Add(myMapIcon) if you want any sort of end-user events. MapIcons get integrated into the map "image" instead of floating on top and cannot react to anything.

以下是设置XAML控件的点和锚点的方法:

Here's how you set the point and anchor for a XAML control:

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

这篇关于地图图钉点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆