如何从asp.net中的图像头找到地理位置 [英] How to find geo-location from image header in asp.net

查看:101
本文介绍了如何从asp.net中的图像头找到地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从asp.net中的图像标题中找到地理位置?



我试过exifflibrary但它没有给出准确答案?



先谢谢。

How to find geo-location from image header in asp.net ?

I tried exifflibrary but it doesn't give accurate answer ?

Thanks in Advance.

推荐答案

我找到了计算纬度和数量的方法。经度位置: -



I found the way to Calculate latitude & longitude position :-

private void ReadImageLatitudeAndLongitude()
   {
       string filePath = @"img\" + "Sunset.jpg";
       string physicalLocation = Server.MapPath(filePath);
       if (File.Exists(physicalLocation))
       {
           Bitmap bmp = new Bitmap(physicalLocation);
           // set Variable Values
           double? latitdue = null;
           double? longitude = null;

           foreach (PropertyItem propItem in bmp.PropertyItems)
           {
               switch (propItem.Type)
               {
                   case 5:
                       if (propItem.Id == 2) // Latitude Array
                           latitdue = GetLatitudeAndLongitude(propItem);
                       if (propItem.Id == 4) //Longitude Array
                           longitude = GetLatitudeAndLongitude(propItem);
                       break;

               }
           }

           Response.Write("Latitude :- "+ latitdue);
           Response.Write("<br/>");
           Response.Write("Latitude :- "+longitude);
       }
   } // ReadImageLatitudeAndLongitude

   private static double? GetLatitudeAndLongitude(PropertyItem propItem)
   {
       try
       {
           uint degreesNumerator = BitConverter.ToUInt32(propItem.Value, 0);
           uint degreesDenominator = BitConverter.ToUInt32(propItem.Value, 4);
           uint minutesNumerator = BitConverter.ToUInt32(propItem.Value, 8);
           uint minutesDenominator = BitConverter.ToUInt32(propItem.Value, 12);
           uint secondsNumerator = BitConverter.ToUInt32(propItem.Value, 16);
           uint secondsDenominator = BitConverter.ToUInt32(propItem.Value, 20);
           return (Convert.ToDouble(degreesNumerator) / Convert.ToDouble(degreesDenominator)) + (Convert.ToDouble(Convert.ToDouble(minutesNumerator) / Convert.ToDouble(minutesDenominator)) / 60) +
                  (Convert.ToDouble((Convert.ToDouble(secondsNumerator) / Convert.ToDouble(secondsDenominator)) / 3600));
       }
       catch (Exception)
       {

           return null;
       }
   } // GetLatitudeAndLongitude


首先,您必须从Exif标头中提取GPS信息(如果有的话)。从这里开始: EXIFextractor库提取EXIF信息 [ ^ ]

比你需要一些反向地理编码服务。您可以从这里开始:使用反向地理编码查找地址 [ ^ ]



exif标头存储设备保存在其中的内容。如果它不够准确,那么你唯一可以做的就是向用户显示已知位置的地图,并要求他将标记放在正确的位置。比存储校正的坐标。
First, you have to extract the GPS information from the Exif header (if any). Start here: EXIFextractor library to extract EXIF information[^]
Than you need some reverse geocoding service. You can start here: Using reverse geocoding to find an address[^]

The exif header is storing what the device saved in it. If it is not accurate enough, than the only thing you can do is to show the user a map with the position known and ask him to place the marker on the right spot. Than store the corrected coordinates.


不要忘记你需要补偿在南半球和西半球发生的负拉特长度。我将此添加到上面的代码中进行补偿。



Don't forget that you will need to compensate for negative lat longs that occur in the Southern and Western hemisphere. I added this to the above code to compensate.

double? latitdue = null;
double? longitude = null;
string ns = null, ew = null;

foreach (PropertyItem propItem in bmp.PropertyItems)
{
    switch (propItem.Type)
    {
        case 2:
            if (propItem.Id == 1) // North or South
                ns = System.Text.Encoding.ASCII.GetString(new byte[1] {propItem.Value[0]});
            if (propItem.Id == 3) // East or West
                ew = System.Text.Encoding.ASCII.GetString(new byte[1] { propItem.Value[0] });
            break;
        case 5:
            if (propItem.Id == 2) // Latitude Array
                latitdue = GetLatitudeAndLongitude(propItem);
            if (propItem.Id == 4) //Longitude Array
                longitude = GetLatitudeAndLongitude(propItem);
            break;
    }
}

if (ew == "W") { longitude = 0 - longitude; }
if (ns == "S") { latitdue = 0 - latitdue; }


这篇关于如何从asp.net中的图像头找到地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆