如何从纬度/液化天然气坐标添加地图标记?视窗 8 手机



我已经从工具箱向应用程序添加了一个地图,但我正在尝试弄清楚如何向地图添加一个标记,该标记将由按钮的单击事件触发。我知道如何获取设备的当前位置,如下所示。

但是,我将如何添加此内容以使用此位置数据在地图上绘制图钉/标记?有没有一种简单的方法可以使用此代码片段中计算出的纬度/lng 添加标记?

Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
    Geoposition geoposition = await geolocator.GetGeopositionAsync(
        maximumAge: TimeSpan.FromMinutes(5),
        timeout: TimeSpan.FromSeconds(10)
        );
    LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00");
    LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
    if ((uint)ex.HResult == 0x80004004)
    {
        // the application does not have the right capability or the location master switch is off
        StatusTextBlock.Text = "location  is disabled in phone settings.";
    }
    //else
    {
        // something else happened acquring the location
    }
}

这比Windows 8要多一些工作:

        var overlay = new MapOverlay { PositionOrigin = new Point(0.5, 0.5), GeoCoordinate = coordinate };
        var img = new Image { Width = 56, Height = 56 };
        img.Source = new BitmapImage { UriSource = new Uri("/Assets/Icons/pin.png", UriKind.Relative) };
        img.Tag = coordinate;
        img.Tap += delegate
        {
            // handle tap
        };
        overlay.Content = img;
        var mapLayer = new MapLayer { overlay };
        map.Layers.Add(mapLayer);

最新更新