使用Bing Map为WP7显示图钉

时间:2011-12-03 08:59:02

标签: windows-phone-7 xml-parsing bing-maps

我正在尝试使用下面的方法在带有WP7的Bing地图中显示位置列表(来自xml文档:使用xml读取),但它不起作用。 当我试图看到我的功能正在阅读时,我发现它没有提取经度。问题出在哪里?

void frloc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            ListBoxItem areaItem = null;
            StringReader wkstream = new StringReader(e.Result);
            XmlReader wkreader = XmlReader.Create(wkstream);

            string areaName = String.Empty;
            string Nom = String.Empty;
            string Photo = String.Empty;
            string Latitude = String.Empty;
            string Longitude = String.Empty;
            string Timing = String.Empty;

            while (wkreader.Read())
            {
                if (wkreader.NodeType == XmlNodeType.Element)
                {
                    switch (wkreader.Name)
                    {
                        case ("name"):
                            {
                                Nom = wkreader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = Nom;

                            } break;
                        case ("photo"):
                            {
                                Photo = wkreader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = Photo;
                            } break;
                        case ("latitude"):
                            {
                                Latitude = wkreader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = Latitude;
                            } break;
                        case ("longitude"):
                            {
                                Longitude = wkreader.ReadElementContentAsString();
                                areaItem = new ListBoxItem();
                                areaItem.Content = Longitude;
                            } break;

                    }
                    double lat, lon;
                    double.TryParse(Latitude, NumberStyles.Any, CultureInfo.InvariantCulture, out lat);
                    double.TryParse(Longitude, NumberStyles.Any, CultureInfo.InvariantCulture, out lon);
                    GeoCoordinate Loc = new GeoCoordinate(lat, lon);

                    Pushpin wkpin = new Pushpin();
                    Image wkpinImage = new Image();
                    wkpin.Content = Nom;
                    wkpinImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://weenek.com/markers/" + Photo, UriKind.Absolute));
                    wkpinImage.Opacity = 0.8;
                    wkpinImage.Stretch = System.Windows.Media.Stretch.None;

                    imageLayer.AddChild(wkpinImage, Loc);
                    map1.Children.Add(wkpin);

xml:

<resultat>
  <ami>
    <id>547</id>
    <nom>Hakim</nom>
    <prenom>Abidi</prenom>
    <latitude>37.01406741589469</latitude>
    <longitude>11.02375026562504</longitude>
    <date>2011-12-02</date>
    <time>01:09:35</time>
    <image>175.jpg</image>
  </ami>
</resultat>

1 个答案:

答案 0 :(得分:0)

您的代码没有任何问题,除非您从未设置过图钉的坐标。

尝试添加

wkpin.Location = Loc;