我有一個需求,我需要顯示特定位置的圖釘。 我已經能夠添加一個自定義圖釘,因爲PushPin類現在已經被棄用了。 爲其代碼如下:Windows Phone應用程序8.1的圖釘類似於Windows地圖應用程序
var location= new Geopoint(new BasicGeoposition() { Latitude = 19.4034, Longitude = 73.8312 });
var pin= CreatePin();
mapper.Children.Add(pin);
MapControl.SetLocation(pin, location);
MapControl.SetNormalizedAnchorPoint(pin, new Point(0.0, 1.0));
mapper.TrySetViewAsync(location, 16, 0, 0, MapAnimationKind.Bow);
代碼自定義CreatePin是:
private DependencyObject CreatePin()
{
//Creating a Grid element.
var myGrid = new Grid();
myGrid.RowDefinitions.Add(new RowDefinition());
myGrid.RowDefinitions.Add(new RowDefinition());
myGrid.Background = new SolidColorBrush(Colors.Transparent);
//Creating a Rectangle
var myRectangle = new Rectangle {Fill = new SolidColorBrush(Colors.Black), Height = 20, Width = 20};
myRectangle.SetValue(Grid.RowProperty, 0);
myRectangle.SetValue(Grid.ColumnProperty, 0);
//Adding the Rectangle to the Grid
myGrid.Children.Add(myRectangle);
//Creating a Polygon
var myPolygon = new Polygon()
{
Points = new PointCollection() {new Point(2, 0), new Point(22, 0), new Point(2, 40)},
Stroke = new SolidColorBrush(Colors.Black),
Fill = new SolidColorBrush(Colors.Black)
};
myPolygon.SetValue(Grid.RowProperty, 1);
myPolygon.SetValue(Grid.ColumnProperty, 0);
//Adding the Polygon to the Grid
myGrid.Children.Add(myPolygon);
return myGrid;
}
我現在能夠顯示自定義腳卻無法顯示title.Is有辦法我可以實現銷如同在Windows地圖應用程序中使用
我得到什麼現在:
我想要什麼:
事情是this.Or如果這是不可能添加標題銷的方式。 請不要建議MapIcon因爲我已經嘗試過了,它不現身mapicon除非放大,還我發現它不太可靠
的MapIcon不保證顯示。當它遮擋地圖上的其他元素或標籤時可能會隱藏。
MapIcon的可選標題不保證顯示。如果看不到文字,請通過減小MapControl的ZoomLevel屬性的值來縮小。
當您顯示指向地圖上特定位置的MapIcon圖像(例如,圖釘或箭頭)時,請考慮將NormalizedAnchorPoint屬性的值設置爲圖像上指針的大致位置。如果將NormalizedAnchorPoint的值保留爲代表圖像左上角的默認值(0,0),則地圖的ZoomLevel中的更改可能會使圖像指向其他位置。
這是好的,如果你想效仿舊形式的推針,但新的API與[MapIcons](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn792121.aspx)似乎是一個更好的選擇 – Petesh
我嘗試過使用這個代碼MapIcon MapIcon1 = new MapIcon(); MapIcon1.Location = new Geopoint(startLocation); MapIcon1.NormalizedAnchorPoint = new Point(0.5,0.5); MapIcon1.Title =「太空針」; mapper.MapElements.Add(MapIcon1);然而,該圖標不會購物,直到放大很多 – Pranjal