如何在windowsphone 8.1中的地图上添加图钉

本文关键字:地图 添加 windowsphone | 更新日期: 2023-09-27 18:26:36

有没有教程或示例显示如何在windowsphone 8.1中添加图钉此代码不起作用:

MapIcon MapIcon1 = new MapIcon();
MapIcon1.Location = new Geopoint(new BasicGeoposition()
{
    Latitude = latitude,
    Longitude = -longitude
 });
 MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
 RestoMap.MapElements.Add(MapIcon1);

如何在windowsphone 8.1中的地图上添加图钉

MapIcon对象不能保证显示在地图上,它们可能会被其他元素遮挡。

如果要放置始终可见的内容,请使用XAML控件:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn792121.aspx#showing_xaml_controls_and_shapes_on_the_map

 <Maps:MapItemsControl x:Name="MapIcons" >
    <Maps:MapItemsControl.ItemTemplate>
        <DataTemplate>
             ........
             .......
        </DataTemplate>
     </Maps:MapItemsControl.ItemTemplate>
 </Maps:MapItemsControl>
class MapIcon
{
   public String id { get; set; }
   public String name { get; set; }
   public String description { get; set; }
   public String picture { get; set; }
   public Geopoint MapLocation { get; set; }
}
funtion
{
     Double latitude = item.latitude;
     Double longitude = item.longitude;
     Geopoint location = new Geopoint(new BasicGeoposition()
     {
        Latitude = latitude,
        Longitude = longitude,
     });
     MapIcon icon = new MapIcon() { MapLocation = location, name = name, picture = picture ,description = description};
     icons.Add(icon);
}
MapIcons.ItemsSource = icons;