请参阅诺基亚地图教程“将图形添加到地图控件”或参阅 MSDN 的“如何在 Windows Phone 8 中将 UIElements 添加到地图控件”。
它主要是围绕添加您自己的 MapLayer,并在其上添加多个 MapOverlay:
private void DrawMapMarkers()
{
MyMap.Layers.Clear();
MapLayer mapLayer = new MapLayer();
// Draw marker for current position
if (MyCoordinate != null)
{
DrawAccuracyRadius(mapLayer);
DrawMapMarker(MyCoordinate, Colors.Red, mapLayer);
}
...
MyMap.Layers.Add(mapLayer);
}
private void DrawMapMarker(GeoCoordinate coordinate, Color color, MapLayer mapLayer)
{
// Create a map marker
Polygon polygon = new Polygon();
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 75));
polygon.Points.Add(new Point(25, 0));
polygon.Fill = new SolidColorBrush(color);
// Enable marker to be tapped for location information
polygon.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
polygon.MouseLeftButtonUp += new MouseButtonEventHandler(Marker_Click);
// Create a MapOverlay and add marker
MapOverlay overlay = new MapOverlay();
overlay.Content = polygon;
overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
}
为了对新的 WP8 Nokia Map 控件进行数据绑定,请使用新Windows Phone Toolkit中的 MapExtensions 。例如,这里是如何使用 MapExtensions 在特定地理坐标中创建PushPin。
<maps:Map x:Name="Map" Grid.Row="1" Hold="OnMapHold">
<maptk:MapExtensions.Children>
<maptk:Pushpin x:Name="RouteDirectionsPushPin" Visibility="Collapsed"/>
<maptk:MapItemsControl Name="StoresMapItemsControl">
<maptk:MapItemsControl.ItemTemplate>
<DataTemplate>
<maptk:Pushpin GeoCoordinate="{Binding GeoCoordinate}" Visibility="{Binding Visibility}" Content="{Binding Address}"/>
</DataTemplate>
</maptk:MapItemsControl.ItemTemplate>
</maptk:MapItemsControl>
<maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Collapsed"/>
</maptk:MapExtensions.Children>
</maps:Map>