StreetView

Topics: General, WPF
Nov 25, 2011 at 1:01 PM
Edited Nov 25, 2011 at 1:42 PM

Hi,

I use a StreetViewToolTip for the CustomMarkerRed that open a popup (User control) and show some information and a thumbnail from StreetView.
The method to show the thumbnail is:

        void loadThumbnail(PointLatLng curPos)
        {
            string lat = curPos.Lat.ToString().Replace(',', '.');
            string lng = curPos.Lng.ToString().Replace(',', '.');
            string urlImg = String.Format("http://cbk0.google.com/cbk?output=thumbnail&w=300&h=96&ll={0},{1}", lat, lng);
            // Download web image
            System.Drawing.Image _Image = null;
            _Image = DownloadImage(urlImg);

            // check for valid image
            if (_Image != null)
            {
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                MemoryStream ms = new MemoryStream();
                _Image.Save(ms, ImageFormat.Bmp);
                ms.Seek(0, SeekOrigin.Begin);
                bi.StreamSource = ms;
                bi.EndInit();
                imgThumnail.Source = bi;
            }
        }

I made a class that retrieve PanoId and the address from a PointLatLng:

    public class StreetViewInf
    {
        public string PanoID { get; set; }
        public string Address { get; set; }
        public string Lat { get; set; }
        public string Lng { get; set; }
        public StreetViewInf(PointLatLng curPosition)
        {
            Lat=curPosition.Lat.ToString().Replace(',', '.');
            Lng=curPosition.Lng.ToString().Replace(',', '.');
            string urlSV = String.Format("http://maps.google.com/cbk?output=xml&ll={0},{1}", Lat, Lng);
            XDocument loaded = XDocument.Load(urlSV);
            var xmlInf = from l in loaded.Descendants("panorama").Descendants("data_properties")
                    select new
                    {
                        PanoID = (string)l.Attribute("pano_id"),
                        Address = String.Format("{0}, {1}, {2}", (string)l.Element("text"), (string)l.Element("region"), (string)l.Element("country"))
                    };
            var inf = xmlInf.ElementAtOrDefault(0);
            if (inf != null)
            {
                PanoID = inf.PanoID;
                Address = inf.Address;
            }
        }
    }

This information can be pass for loading a Window like in Demo.StreetView project from Testing folder.

In my project I open this window using a ContextMenu for CustomMarkerRed.

I hope to be usefull for someone.

Once again Thank You for sharing this project !