开发者

lat/long binding into map from xml parsing wp7

I was given a task to parse xml from web server and get user information including lat/long nickname and images, then binding them to the map (there are a lot of them). I use WebClient and XDocument to working with parsing. What is the type of lat/long and how to binding them to the map?

        void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        using (var reader = new StreamReader(e.Result))
        {
            //  string[] _elements = { "one", "two", "three" }; 
            int[] counter = { 1 };
            string s = reader.ReadToEnd();
            Stream str = e.Result;
            str.Position = 0;
            XDocument xdoc = XDocument.Load(str);

            var data = from query in xdoc.Descendants("position")
                       select new mapping
                       {
                  //         color = counter[0]++,
                           album = (string)query.Element("album"),
                           track = (string)query.Element("track"),
                           artist = (string)query.Element("artist"),
                       开发者_StackOverflow中文版    nickname = (string)query.Element("user_info").Element("nickname"),
                           pos_lat = (GeoCoordinate)query.Element("lat"),

                       };
            //   lb1.ItemsSource = data;   
    //        listbox1.ItemsSource = data;
        }
    }


    public class mapping
    {
        public int index { get; set; }
        public string album { get; set; }
        public string track { get; set; }
        public string artist { get; set; }
        public GeoCoordinate pos_lat { get; set; }
        public GeoCoordinate pos_lon { get; set; }
        public string nickname { get; set; }
    }


<Microsoft_Phone_Controls_Maps:Map Height="427" HorizontalAlignment="Left" Margin="12,6,0,0" Name="map1" VerticalAlignment="Top" Width="438" />


I think you misunderstood that GeoCoordinate is for. GeoCoordinate is a coordinate, representing the latitude, longitude and some other geographical location properties.

The value(s you're reading out is a double, that represent either the latitude or the longitude. You simply can't cast a double to a GeoCoordinate , and it certainly doesn't make sense to have a seperate GeoCoordinate for both latitude and longitude.

So what you need to do is just to read out the latitude and longitude as doubles, and then create a GeoCoordinate based on that.

Use Double.TryParse for handling the conversion (as you're reading out all values as string initially)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜