Muliple Pushpins in Windows Phone 8.1

我的梦境 提交于 2019-12-13 03:56:44

问题


I am using MapControl to display map. I have MapServiceToken too. I have added custom pushpin using MapIcon and assigned this object to Map. It is working fine. But when i try to add multiple pushpins using same scenario and assign it to map so i am getting last pushpin on the map. Rest of other pushpins are not getting visible. Kindly tell me any simple solution to this problem. Thanks


回答1:


You can binding your pushpins on map without MapIcon.

Add in xaml

<Maps:MapControl x:Name="MapLocationsControl" MapServiceToken="add your token here">
        <Maps:MapItemsControl x:Name="mapitem">
            <Maps:MapItemsControl.ItemTemplate>
                <DataTemplate>

                        <Image Height="50" Width="50"
                               Source="{Binding image,Mode=OneWay}"
                       Maps:MapControl.Location="{Binding Geopoint}"/>

                </DataTemplate>
            </Maps:MapItemsControl.ItemTemplate>
        </Maps:MapItemsControl>
    </Maps:MapControl>

And in c# binding items in MapControl source

 mapitem.ItemsSource = items;

Where items is observable collection with MapItems class items. You can add items with Add().

ObservableCollection<MapItem> items = new ObservableCollection<MapItem>();

items.Add(new MapItem(lat,lng, "Assets/pushpinicon.png"));

MapItem Class is like this

public class MapItem {

public Geopoint Geopoint { get; set; }

public string image {get; set;}

    public MapItem(double lat , double lng , string img)
    {

        Geopoint = new Geopoint(new BasicGeoposition() { Latitude = lat, Longitude = lng });

        image=img;
     }
}


来源:https://stackoverflow.com/questions/33471206/muliple-pushpins-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!