Windows Phone Map控件上的自定义标记

时间:2014-12-24 22:49:42

标签: windows-phone-8

我使用此代码将自定义标记添加到BING地图控件。 Map组件无法绘制Image(),但文本工作正常。我错了吗?

private void AddMarkerToMap(double Latitude, double Longitude, string Name)
{
    Image markerImg = new Image { Width = 63, Height = 46 };
    Uri imgUri = new Uri("Images/GeoPin.png", UriKind.RelativeOrAbsolute);
    if (imgUri == null)
    {
        throw new Exception("Image can't be find");
    }
    markerImg.Source = new BitmapImage(imgUri);
    markerImg.Tag = Name;
    //markerImg.Tap += delegate
    //{
    //    // handle tap
    //};

    var overlay = new MapOverlay
    {
        PositionOrigin = new Point(0.5, 0.5),
        GeoCoordinate = new GeoCoordinate(Latitude, Longitude),
        Content = markerImg,
        //Content = Name,
    };

    var mapLayer = new MapLayer { overlay };
    MyMap.Layers.Add(mapLayer);
}

3 个答案:

答案 0 :(得分:0)

如果要向Map添加图钉,请使用MapIcon类。这可以显示图像和文本。

private void AddMapIcon()
{
    MapIcon MapIcon1 = new MapIcon();
    MapIcon1.Location = new Geopoint(new BasicGeoposition() { Latitude = 47.620, Longitude = -122.349 });
    MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
    MapIcon1.Title = "Space Needle";
    MapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/customicon.png"));
    MapControl1.MapElements.Add(MapIcon1);
}

答案 1 :(得分:0)

Mapicon是否存在于Windows Phone 8 SDK中?

答案 2 :(得分:0)

您可以使用Phone.Controls.Toolkit将自定义Pushpin作为map上的图片。

参考:Image as pushpin on maps - Windows phone 8