我面临的问题是,当我为 mapicon 添加图像时,感觉就像地图已从地图中删除了。
BasicGeoposition bg = new BasicGeoposition() { Latitude = 33.98151688, Longitude = 35.63329697 };
Geopoint snPoint = new Geopoint(bg);
MapIcon mapIcon1 = new MapIcon();
mapIcon1.Location = snPoint;
mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx://Assets/MapPin.png"));
mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
MyMap.MapElements.Add(mapIcon1);
如果我删除了mapIcon1.Image,它会显示一个默认的针脚点。
我正在使用VS 2015,UWP项目。
答案 0 :(得分:0)
方法RandomAccessStreamReference.CreateFromUri
围绕指定的URI创建随机访问流。有效的URI方案是http,https,ms-appx和ms-appdata。
使用ms-appx方案引用来自应用程序包(see App packages and deployment)的应用程序文件。这些文件通常是静态图像,数据,代码和布局文件。
ms-appx方案的URI权限是包清单中定义的包标识名称。因此,它以URI形式限制为包标识名称中允许的字符集。包名称仅限于当前正在运行的应用程序包依赖关系图中的名称。
例如:
Package package = Package.Current;
PackageId packageId = package.Id;
String output = packageId.Name;
string str = string.Format("ms-appx://{0}/Assets/Map-512.png", output);
mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri(str));
当给定的权限为空时,权限的值是当前正在运行的应用程序包。
例如:
mapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Map-512.png"));
更多信息,请参阅URI schemes。
答案 1 :(得分:0)
BasicGeoposition geoPosition = new BasicGeoposition();
geoPosition.Latitude = 27.175015;
geoPosition.Longitude = 78.042155;
// get position
Geopoint myPoint = new Geopoint(geoPosition);
//create POI
MapIcon myPOI = new MapIcon { Location = myPoint, Title = "My Position", NormalizedAnchorPoint = new Point(0.5, 1.0), ZIndex = 0 };
// Display an image of a MapIcon
myPOI.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pin.png"));
// add to map and center it
MyMap.MapElements.Add(myPOI);
MyMap.Center = myPoint;
MyMap.ZoomLevel = 10;
MapScene mapScene = MapScene.CreateFromLocationAndRadius(new Geopoint(geoPosition), 500, 150, 70);
await MyMap.TrySetSceneAsync(mapScene);