我正在尝试创建一个地图应用程序,但我找到的示例描述了我的myMap.Children
对象没有的myMap
列表: - (
我已经创建了一张地图,非常简单:
<maps:Map Visibility="Collapsed" Name="MyMap" Height="670" Width="400" ZoomLevel="10" Pitch="0" CartographicMode="Hybrid" Margin="30,0" />
那么我怎样才能在C#中添加PushPins,并且这些是否有来自Assets
的图像?
答案 0 :(得分:9)
请参阅“Adding Graphics to a Map control”上的诺基亚地图教程,或参阅MSDN的“How to add UIElements to a Map control in Windows Phone 8”。
主要是在它上面加上你自己的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诺基亚地图控件进行数据绑定,请使用新Windows Phone Toolkit中的MapExtensions。例如,这里使用MapExtensions how to create a PushPin in a specific GeoCoordinate。
<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>