【问题标题】:Android location change Latitude and Longitude from DMS format to doubleAndroid 位置将经纬度从 DMS 格式更改为双倍
【发布时间】:2016-01-10 19:50:56
【问题描述】:

我有这种位置格式 (24°13'30.92"N,55°45'51.94"E),我需要通过 android 将其转换为像 (24.225275, 55.764417) 这样的双精度值。

我尝试了类似的方法,但没有成功

String lonStr="24°13'30.92"N";
Double lon=Location.convert(lonStr);

【问题讨论】:

  • 值在degree,minute ,second 和方向
  • 是的,我知道,我想将其转换为双精度值
  • 在您的onLocationChange(Location location) 中访问location.getLongitude()location.getLatitude()
  • substringindexOf 将帮助您检查我的答案。

标签: android google-maps location latitude-longitude


【解决方案1】:

使用substringindexOf

提取分钟分别除以603600和 最后加上degree部分。

    String str="24°13'30.92\"N,55°45'51.94\"E";

    String s[]=str.split(",");
    double lat=Integer.parseInt(s[0].substring(0,s[0].indexOf("°")))+(double)Integer.parseInt(s[0].substring(s[0].indexOf("°")+1, s[0].indexOf("'")))/60+ Double.parseDouble(s[0].substring(s[0].indexOf("'")+1, s[0].indexOf("\"")))/3600;

  // same for longitude
   System.out.println(String.format("%.6f", lat));

输出:

24.225256

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    相关资源
    最近更新 更多