图片文件位于我的应用的资源文件夹中。我使用完整的uri没有成功。我尝试将其动态添加到我的地图中。其余的代码工作(测试),当我试图从uri获取图像时,我得到这个错误。
Image pin = new Image();
var uri = new Uri(@"/Assets/shop.png", UriKind.RelativeOrAbsolute);
pin.Source = new BitmapImage(uri);
pin.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
pin.MouseLeftButtonUp += new MouseButtonEventHandler(Marker_Click);
pin.Height = 20;
pin.Width = 20;
pin.Opacity = 50;
// Create a MapOverlay and add marker.
MapOverlay overlay = new MapOverlay();
overlay.Content = pin;
overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
答案 0 :(得分:0)
试试这个:
Image imgPushpin = new Image();
imgPushpin.Height = 60;
imgPushpin.Width = 41;
imgPushpin.Source = new BitmapImage(new Uri("/Assets/Images/PropertyLocator/imgPropertyPoint.png", UriKind.Relative));
imgPushpin.Tag = "Location";
imgPushpin.MouseLeftButtonUp += imgPushpinMouseLeftButtonUp;
// Create a MapOverlay and add marker
MapOverlay overlay = new MapOverlay();
overlay.Content = imgPushpin;
overlay.GeoCoordinate = new GeoCoordinate(listView[j].latitude, listView[j].longnitude);
overlay.PositionOrigin = new Point(0.5, 1);
locationLayer = new MapLayer();
locationLayer.Add(overlay);
mapPropertyLocator.Layers.Add(locationLayer);
mapPropertyLocator.ZoomLevel = 11.5;