Windows phone 8 如何将事件处理程序添加到WP8中的MapPolygons?

Windows phone 8 如何将事件处理程序添加到WP8中的MapPolygons?,windows-phone-8,here-api,Windows Phone 8,Here Api,我目前有一个Windows Phone 8应用程序,其中有一个地图,我正在地图中添加一个MapPolygon 我想向MapPolygon添加一个事件处理程序,以便我可以“点击”MapPolygon,它将导航到另一个页面 但是,MapElements没有内置的“手势”处理 以下是我尝试过的: 通过NuGet,我添加了Windows Phone工具包包 我尝试创建一个“手势服务”,并对MapPolygon应用“点击”事件/手势 下面是代码的样子: var poly_gesture = Gestu

我目前有一个Windows Phone 8应用程序,其中有一个地图,我正在地图中添加一个MapPolygon

我想向MapPolygon添加一个事件处理程序,以便我可以“点击”MapPolygon,它将导航到另一个页面

但是,MapElements没有内置的“手势”处理

以下是我尝试过的:

  • 通过NuGet,我添加了Windows Phone工具包包
  • 我尝试创建一个“手势服务”,并对MapPolygon应用“点击”事件/手势
下面是代码的样子:

var poly_gesture = GestureService.GetGestureListener(poly);
poly_gesture.Tap += new EventHandler<GestureEventArgs>(Poly_Tap);


private void Poly_Tap(object sender, GestureEventArgs e)
{
    // Handle the event here.
}
var poly\u-signature=GestureService.getgesturestener(poly);
poly_手势.Tap+=新事件处理程序(poly_Tap);
私有void Poly_Tap(对象发送器、GestureEventArgs e)
{
//在这里处理事件。
}
问题是Poly_-Tap方法永远不会被触发。 “GestureService”显示一条警告,指出它现在已经“过时”,尽管我已经安装了Windows Phone Toolkit软件包。是否有新的/更好的/不同的方法为MapElement创建手势/事件处理程序


谢谢

以下是我提出的解决方案:

// A method that gets called when a user clicks on a map.
    private void map1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {

        // When a user clicks the map, turn this into a GPS location.
        var point = e.GetPosition(map1);
        var location = map1.ConvertViewportPointToGeoCoordinate(point);

        // Make variables to store the latitude and longitude.
        double smallest_lat = 0; 
        double largest_lat = 0;
        double smallest_long = 0;
        double largest_long = 0;

        // Loop through each coordinate of your Polygon
        foreach (GeoCoordinate gc in poly.Path)
        {
            // Store the values of the first GPS location
            //  into the variables created above
            if (smallest_lat == 0)
            {
                smallest_lat = gc.Latitude;
                largest_lat = gc.Latitude;
                smallest_long = gc.Longitude;
                largest_long = gc.Longitude;
            }

            // For each new GPS coordinate check to see if it is 
            //  smaller/larger than the previous one stored.
            if (gc.Latitude < smallest_lat) { smallest_lat = gc.Latitude; }
            if (gc.Latitude > largest_lat) { largest_lat = gc.Latitude; }
            if (gc.Longitude < smallest_long) { smallest_long = gc.Longitude; }
            if (gc.Longitude > largest_long) { largest_long = gc.Longitude; }

        }

        // Call the "isWithin" function to identify if where
        //  the user clicked is within the Polygon you're looking at. 
        btnPoly.Content = isWithin(location, smallest_lat, largest_lat, smallest_long, largest_long);

    }

    // A function that determines if a user clicks withing a specified rectangle
    public Boolean isWithin(GeoCoordinate clicked_gc, double smallest_lat, double largest_lat, double smallest_long, double largest_long)
    {

        bool slat = clicked_gc.Latitude >= smallest_lat;
        bool llat = clicked_gc.Latitude <= largest_lat;
        bool slong = clicked_gc.Longitude >= smallest_long;
        bool llong = clicked_gc.Longitude <= largest_long;

        // Returns 'true' if the user clicks in the defined coordinates
        // Returns 'false' if the user doesn't click in the defined coordinates
        return slat && llat && slong && llong;
    }
//当用户单击地图时调用的方法。
私有void map1_Tap(对象发送方,System.Windows.Input.GestureEventArgs e)
{
//当用户单击地图时,将其转换为GPS位置。
变量点=e.GetPosition(map1);
var location=map1.convertViewPortPointToGeoCoordination(点);
//制作变量以存储纬度和经度。
双最小值_lat=0;
双倍最大值=0;
双最小_长=0;
双最大长度=0;
//循环遍历多边形的每个坐标
foreach(多边形路径中的地理坐标gc)
{
//存储第一个GPS位置的值
//进入上面创建的变量
如果(最小值=0)
{
最小纬度=总纬度;
最大纬度=总纬度;
最小经度=总经度;
最大经度=总经度;
}
//对于每个新的GPS坐标,检查其是否正确
//比存储的上一个更小/更大。
如果(总纬度<最小纬度){最小纬度=总纬度;}
如果(gc.Latitude>maximum_lat){maximum_lat=gc.Latitude;}
如果(gc.Longitudemaximust_long){maximust_long=gc.Longitude;}
}
//调用“isWithin”函数以确定
//单击的用户位于您正在查看的多边形内。
btnPoly.Content=isWithin(位置、最小纬度、最大纬度、最小长度、最大长度);
}
//确定用户是否使用指定矩形单击的函数
公共布尔值在范围内(地理坐标单击\u gc、双最小\u lat、双最大\u lat、双最小\u long、双最大\u long)
{
bool slat=单击的纬度>=最小纬度;
bool llat=点击的纬度=最小的长度;

bool llong=clicked_gc.longide有一个API可以为您执行此操作:GetMapElementsAt(point)。它将返回给定位置的所有MapElements。谢谢……这会简单得多!