问题描述
我正在工作一个WP7项目,并尝试以特定方式将图钉连接到bing映射,但它只是行不通.似乎可以正常读取XML文件,因为它计算了所有项目,然后加载了地图,但只是将黑色图钉放在了地图的右上角.对于任何想法,为什么它不会使图钉失望,将不胜感激.非常感谢.我想我已经包含了所有相关的代码.
Im working a a WP7 project, and try to bing pushpins to bing maps a particular way, but it just wont work. It seems to read the XML file ok as it counts all the items, and then loads the map, but just puts the black pushpin in the top right hand corner of the map. Would be grateful for any ideas why its not dispalying the pushpins. Many thanks.I think I have included all the relevent code..
namespace maps_data_test_2
{
public class LocationData
{
public Location Location
{
get;
set;
}
public String CustomerName
{ get; set; }
public Int32 CustomerId
{ get; set; }
public LocationData()
{
this.Location = new Location();
}
}
/// <summary>
/// This class exposes IEnumerable, and acts as ItemsSource for
/// MapItemsControl
/// </summary>
public class LocationDataCollection : ObservableCollection<LocationData>
{
public bool IsDataSource
{
get
{
return true;
}
set
{
this.Load();
}
}
public LocationDataCollection()
{
}
public void Load()
{
Uri url = new Uri("http://www.equestrian-photo.com/CustomerData.xml", UriKind.Absolute);
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(url);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
Double Lat = 0.00;
Double Lng = 0.00;
String CustomerName = "";
Int32 CustomerId = 0;
LocationDataCollection locationList = new LocationDataCollection();
while (reader.Read())
{
reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Element)
{
reader.MoveToFirstAttribute();
}
if (reader.NodeType == XmlNodeType.Attribute)
{
if (true == reader.MoveToAttribute("Latitude"))
{
Lat = reader.HasValue ? Convert.ToDouble(reader.Value) : 0.00;
}
if (true == reader.MoveToAttribute("Longitude"))
{
Lng = reader.HasValue ? Convert.ToDouble(reader.Value) : 0.00;
}
if (true == reader.MoveToAttribute("CustomerName"))
{
CustomerName = reader.Value.ToString();
}
if (true == reader.MoveToAttribute("CustID"))
{
CustomerId = Convert.ToInt32(reader.Value);
}
LocationData T = new LocationData();
T.Location.Latitude = Lat;
T.Location.Longitude = Lng;
T.CustomerName = CustomerName;
locationList.Add(T);
}
}
IEnumerator ppEnum = locationList.GetEnumerator();
while (ppEnum.MoveNext())
{
this.Add((LocationData)ppEnum.Current);
}
reader.Close();
}
}
}
}
Xaml代码:
<phone:PhoneApplicationPage
x:Class="maps_data_test_2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:t="clr-namespace:maps_data_test_2"
xmlns:m ="clr-名称空间:Microsoft.Phone.Controls.Maps; assembly = Microsoft.Phone.Controls.Maps"
xmlns:m="clr- namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="LogoTemplate">
<m:Pushpin Location="{Binding Location}" />
</DataTemplate>
<t:LocationDataCollection x:Key="LocationList" IsDataSource="True"/>
<Grid>
<m:Map Height="450" Width="450" x:Name="mMap" Cred entialsProvider=""
Mode="Road"
>
<m:MapItemsControl x:Name="ListOfItems"
ItemTemplate="{StaticResource LogoTemplate}"
ItemsSource="{StaticResource LocationList}">
</m:MapItemsControl>
</m:Map>
</Grid>
</phone:PhoneApplicationPage>
推荐答案
@Dan将LocationData集合作为属性,并且类型为ObservableCollection.您可以将数据填充到此集合中.
@Dan Have the LocationData collection as a property, and as of type ObservableCollection. And you can populate the data into this collection.
这篇关于将图钉绑定到Bing地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!