如何让latititude和图像的经度,以SD卡为我的应用程序? [英] How to get the latititude and longitude of an image in sdcard to my application?

查看:121
本文介绍了如何让latititude和图像的经度,以SD卡为我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的应用程序可以打开gallery.Is有什么办法让纬度和任何所选图像的经度,以画廊为我application.Any想法,请帮忙提前me.Thanks

From my application I can open gallery.Is there any way to get latitude and longitude of any selected image in gallery to my application.Any ideas please help me.Thanks in advance

推荐答案

您应该用的 ExifInterface 类读取图像的各种EXIF元数据:

You Should Go with ExifInterface class to read various EXIF metadata from Images:

例如:

ExifInterface exif = new ExifInterface(filepath);
exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

编辑:

现在在这里,您将得到经纬度,只要下面的格式。

Now Here you will get lat-long as Below format.

经纬度= 30 / 1,12 / 1,34 / 1, 长= 81 / 1,22 / 1,41 / 1

lat = 30/1,12/1,34/1, long=81/1,22/1,41/1

要转换到这一实际值的这个博客帮助了我。

To Convert this into Real Values this Blog Helped Me.

我们需要从度,分,秒形式的GeoPoint形式做转换。

we need to do conversion from degree, minute, second form to GeoPoint form.

通过以下方式,你可以做到这一点。

By Below Way you can Do it.

 String LATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
 String LATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
 String LONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
 String LONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

 // your Final lat Long Values
 Float Latitude, Longitude;

 if((LATITUDE !=null)
   && (LATITUDE_REF !=null)
   && (LONGITUDE != null)
   && (LONGITUDE_REF !=null))
 {

  if(LATITUDE_REF.equals("N")){
   Latitude = convertToDegree(LATITUDE);
  }
  else{
   Latitude = 0 - convertToDegree(LATITUDE);
  }

  if(LONGITUDE_REF.equals("E")){
   Longitude = convertToDegree(LONGITUDE);
  }
  else{
   Longitude = 0 - convertToDegree(LONGITUDE);
  }

 }

private Float convertToDegree(String stringDMS){
 Float result = null;
 String[] DMS = stringDMS.split(",", 3);

 String[] stringD = DMS[0].split("/", 2);
    Double D0 = new Double(stringD[0]);
    Double D1 = new Double(stringD[1]);
    Double FloatD = D0/D1;

 String[] stringM = DMS[1].split("/", 2);
 Double M0 = new Double(stringM[0]);
 Double M1 = new Double(stringM[1]);
 Double FloatM = M0/M1;

 String[] stringS = DMS[2].split("/", 2);
 Double S0 = new Double(stringS[0]);
 Double S1 = new Double(stringS[1]);
 Double FloatS = S0/S1;

    result = new Float(FloatD + (FloatM/60) + (FloatS/3600));

 return result;


};



@Override
public String toString() {
 // TODO Auto-generated method stub
 return (String.valueOf(Latitude)
   + ", "
   + String.valueOf(Longitude));
}

public int getLatitudeE6(){
 return (int)(Latitude*1000000);
}

public int getLongitudeE6(){
 return (int)(Longitude*1000000);
}

这篇关于如何让latititude和图像的经度,以SD卡为我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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