示例#1
0
        public static ConvertBing gcj02_To_Wgs84(double lat, double lon)
        {
            ConvertBing info      = new ConvertBing();
            ConvertBing gps       = transform(lat, lon);
            double      lontitude = lon * 2 - gps.getLongitude();
            double      latitude  = lat * 2 - gps.getLatitude();

            info.setChina(gps.IsChina());
            info.setLatitude(latitude);
            info.setLongitude(lontitude);
            return(info);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //打开图片
            OpenFileDialog openfiledialog = new OpenFileDialog
            {
                Filter = "图像文件|*.jpg;*.png;*.jpeg;*.bmp;*.gif|所有文件|*.*"
            };

            if ((bool)openfiledialog.ShowDialog())
            {
                photo.Source = new BitmapImage(new Uri(openfiledialog.FileName));
            }

            string filename = openfiledialog.FileName;

            exifmessage.Text = filename;
            StringBuilder sb          = new StringBuilder();
            var           directories = ImageMetadataReader.ReadMetadata(filename);
            StringBuilder latitude    = new StringBuilder();
            StringBuilder longgitude  = new StringBuilder();

            //经度输出
            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                {
                    if ($"{tag.Name}" == "GPS Latitude")
                    {
                        sb.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        latitude.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        exifmessage.Text = sb.ToString();
                    }
                }
            }
            //纬度输出
            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                {
                    if ($"{tag.Name}" == "GPS Longitude")
                    {
                        sb.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        longgitude.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        exifmessage.Text = sb.ToString();
                    }
                }
            }
            //时间输出
            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                {
                    if ($"{tag.Name}" == "Date/Time")
                    {
                        sb.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        longgitude.AppendLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                        exifmessage.Text = sb.ToString();
                    }
                }
            }
            //转换经纬度
            double      newlatitude   = 0;
            double      newlonggitude = 0;
            GCJ02_WGS84 gCJ02_WGS84   = new GCJ02_WGS84();
            ConvertBing convertBing   = new ConvertBing();
            GPSConvert  gPSConvert    = new GPSConvert();

            newlatitude           = gPSConvert.getlatitude(latitude);
            newlonggitude         = gPSConvert.getlonggitude(longgitude);
            convertBing           = GCJ02_WGS84.wgs84_To_Gcj02(newlatitude, newlonggitude);
            latitudemessage.Text  = "经度:" + convertBing.getLatitude().ToString("#0.000");
            longitudemessage.Text = "纬度:" + convertBing.getLongitude().ToString("#0.000");

            //生成图钉
            Pushpin  pushpin  = new Pushpin();
            MapLayer mapLayer = new MapLayer();

            pushpin.MouseRightButtonDown += RemovePushpin;
            pushpin.Location              = new Location(convertBing.getLatitude(), convertBing.getLongitude());
            this.mapLayer.AddChild(pushpin, pushpin.Location);
            bingMap.Center    = new Location(convertBing.getLatitude(), convertBing.getLongitude());
            bingMap.ZoomLevel = 14;

            //图钉标注
            var image = new Image {
                Width = 200, Height = 200, Margin = new Thickness(8)
            };

            image.Source = new BitmapImage(new Uri(openfiledialog.FileName));
            ToolTipService.SetToolTip(pushpin, image);

            //生成轨迹
            if (flag > 0)
            {
                MapPolyline polyline      = new MapPolyline();
                Location    startlocation = new Location(latTag, longTag);
                Location    endlocation   = new Location(convertBing.getLatitude(), convertBing.getLongitude());
                polyline.Locations = new LocationCollection
                {
                    new Location(startlocation),
                    new Location(endlocation)
                };

                polyline.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                polyline.StrokeThickness = 5;
                polyline.Opacity         = 1;//不透明度
                this.mapLayer.Children.Add(polyline);
                polyline.MouseRightButtonDown += RemovePolyline;
            }
            latTag  = convertBing.getLatitude();
            longTag = convertBing.getLongitude();
            flag++;
        }